Week 12 November 14 • Homework 3, Part 1

advertisement
1
Week 12
November 14
• Homework 3, Part 1
• Physical Database Design and Denormalization
R. Ching, Ph.D. • MIS • California State University, Sacramento
Confirmation number: MCWY123
Date: November 11, 2001
AAdvantage Number: ABC123456
Mr. Moki Mao
1234 Kama`aina Place, Honolulu, HI 96821
Date
Airline
Jan 17, 01 United
Jan 17, 01 American
Jan 20, 01 Hawaiian
Jan 23, 01 Hawaiian
Jan 26, 01 Hawaiian
Jan 26, 01 Hawaiian
Jan 25, 01 United
Flight/Class Depart
Arrive
Seat
Sacarmento-Los Angeles
UA2503 Y 9:39A
11:09A
12A
Los Angeles-Honolulu
AA297 F
2:00P
5:56P
25H
Honolulu-Kahalui, Maui
HA116 Y
9:10A
9:45A
9A
Kahalui, Maui-Kona
HA138 Y
9:10A
9:38A
17C
Kona-Honolulu
HA162 Y
10:35A
11:43A
17A
Honolulu-San Francisco
HA12 F
1:30P
8:25P
22G
San Francisco-Sacramento
UA5363 Y 10:00P
10:45P
R. Ching, Ph.D. • MIS • California State University, Sacramento
5A
2
Service
Normalized Relations
Itineraries (Confirmation_number, itinerary_date, AAdvantage_number)
Customers (AAdvantage_number, customer_name, address, zip_code)
Zip_codes (Zip_code, city, state)
Reservations (Confirmation_number, flight_number, flight_date, seat, class)
Flights (Flight_number, airline, departure_time, arrival_time, origin,
destination, food_service, movie)
R. Ching, Ph.D. • MIS • California State University, Sacramento
3
Normalized Relations
Itineraries (Confirmation_number, itinerary_date, AAdvantage_number)
Customers (AAdvantage_number, customer_name, address, zip_code)
Zip_codes (Zip_code, city, state)
Reservations (Confirmation_number, Airline_code, flight_number, flight_date,
seat, class)
Flights (Airline_code, Flight_number, airline, departure_time, arrival_time,
origin, destination, food_service, movie)
Airlines (Airline_code, Airline_company)
If Flight_number is a composite key of
Airline_code and Flight_number
R. Ching, Ph.D. • MIS • California State University, Sacramento
4
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Consist of
Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Zip_codes
Zip_code
City
State
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
5
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Consist of
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
 Locate
Partial relationship
1..1
Zip_codes
Zip_code
City
State
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
6
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Consist of
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Partial relationship
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Zip_codes
Zip_code
City
State
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
7
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Consist of
Have
Strong
0..*
Entity
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
Mandatory relationship
0..*
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Weak Entity
Zip_codes
Zip_code
City
State
Key of Itineraries is part of
the key for Reservations
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
8
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Consist of
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Strong Entity
Zip_codes
Zip_code
City
State
Partial relationship
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Weak Entity Airline_code
Arrival_time
0..*
1..1 Airline
Origin
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
9
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Consist of
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..* Entity
Weak
Reserve
1..1
1..1
Zip_codes
Zip_code
City
State
Partial
relationship
Flights
Strong Entity
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
10
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Consist of
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Zip_codes
Zip_code
City
State
Logical Design
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
11
Physical Database Design
• Implement constraints
– Required data (not null)
– Domain constraints (check, references)
– Multiplicity
– Entity integrity (primary key)
– Referential integrity (foreign key)
– General constraints (business rules)
• How can the logical database design be “enhanced” for
the physical design?
R. Ching, Ph.D. • MIS • California State University, Sacramento
12
Physical Database Design: Indexing
• Index the primary key (if it is not the key of the file
organization)
• Do not index small relations
• Add a secondary index to a heavily used secondary key
• Add a secondary index to a frequently used foreign key
AVOID INDEXING AN ATTRIBUTE OR RELATION
THAT IS FREQUENTLY UPDATED
• Avoid indexing an attribute if the query will retrieve a
large portion of the tuples in a relation
• Avoid indexing attributes that consist of long character
strings
R. Ching, Ph.D. • MIS • California State University, Sacramento
13
Physical Database Design
• In SQL…
Create index index-name on table-name
(column-name1 {asc|desc}, …, column-namen {asc|desc});
• For example…
Create index video_sales on video_sales
(rating, distributor_code, category_code);
R. Ching, Ph.D. • MIS • California State University, Sacramento
14
Physical Database Design
15
• Domain constraint
– External reference (dynamic values)
create table…
SQL video_rating varchar2(5) constraint dc_product_code
references products(product_code));
Index name
Table name and column name (provided the column has been defined
as unique when the table was created)
– Internal reference (static values)
create table…
SQL seat_capacity smallint
constraint ck_seat_capacity check (seat_capacity between 1 and 12));
Index name
R. Ching, Ph.D. • MIS • California State University, Sacramento
Static values
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
Have
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Physical Database
Design:1..1Denormalization
1..1
0..*
Consist of
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Zip_codes
Zip_code
City
State
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
16
Denormalization
• Duplicating attributes or combining relations
– Combining 1:1 relationships
– Duplicating nonkey attributes in 1:M relationships to
reduce joins (creating partial or transitive dependencies)
– Reference tables (introducing transitive dependencies
by reducing the number of joins)
– Duplicating foreign key attributes in 1:M relationships
to reduce joins
– Duplicating attributes in M:N relationships to reduce
joins
R. Ching, Ph.D. • MIS • California State University, Sacramento
17
Denormalization
• Duplicating attributes or combining relations (cont.)
– Introducing repeating groups (if the number of
occurrences is known and/or constant)
– Creating extract tables (in an extreme case, an
unnormalized relation) - frees computing resources
– Introduction of “codes” to
• Simplify the composite key
• Retain the original sequence
R. Ching, Ph.D. • MIS • California State University, Sacramento
18
Itineraries
Confirmation_number
Itinerary_date
AAdvantage_number (fk)
1..1
Have
0..*
1..1
Customers
AAdvantage_number
Customer_name
Address
Zip_code (fk)
0..*
Consist of
 Locate
1..*
Reservations
Confirmation_number (fk)
Airline_code (fk)
Flight_number (fk)
Flight_date
Seat
Class
0..*
Reserve
1..1
1..1
Zip_codes
Zip_code
City
State
Flights
Airline_code (fk)
Flight_number
Departure_time
Airlines
Offer
Arrival_time
Airline_code
0..*
1..1
Origin
Airline
Destination
Food_service
R. Movie
Ching, Ph.D. • MIS • California State University, Sacramento
19
20
R. Ching, Ph.D. • MIS • California State University, Sacramento
Download