200 likes | 218 Views
Week 12 November 14. Homework 3, Part 1 Physical Database Design and Denormalization. Confirmation number: MCWY123 Date: November 11, 2001. AAdvantage Number: ABC123456 Mr. Moki Mao 1234 Kama`aina Place, Honolulu, HI 96821. Date. Airline. Flight/Class. Depart. Arrive. Seat.
E N D
Week 12November 14 Homework 3, Part 1 Physical Database Design and Denormalization
Confirmation number: MCWY123 Date: November 11, 2001 AAdvantage Number: ABC123456 Mr. Moki Mao 1234 Kama`aina Place, Honolulu, HI 96821 Date Airline Flight/Class Depart Arrive Seat Service Jan 17, 01 Jan 17, 01 Jan 20, 01 Jan 23, 01 Jan 26, 01 Jan 26, 01 Jan 25, 01 United American Hawaiian Hawaiian Hawaiian Hawaiian United 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 5A
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)
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
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 0..* Consist of Locate 1..* 1..1 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State 0..* Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 0..* Consist of Partial relationship Locate 1..* 1..1 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State 0..* Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 Partial relationship 0..* Consist of Locate 1..* 1..1 1..1 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State 0..* Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have Strong Entity 0..* 1..1 1..1 0..* Mandatory relationship Consist of Locate 1..* 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State Weak Entity Key of Itineraries is part of the key for Reservations 0..* Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 0..* Consist of Locate 1..* 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State Strong Entity 0..* Partial relationship Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer Weak Entity 0..* 1..1
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 0..* Consist of Locate 1..* 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State Weak Entity 0..* Reserve 1..1 Partial relationship Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Strong Entity Airlines Airline_code Airline Offer 0..* 1..1
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 0..* Consist of Locate 1..* 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State 0..* Logical Design Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1
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?
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
Physical Database Design • In SQL… • For example… Create indexindex-nameontable-name (column-name1 {asc|desc}, …, column-namen {asc|desc}); Create index video_sales on video_sales (rating, distributor_code, category_code);
Physical Database Design • Domain constraint • External reference (dynamic values) • Internal reference (static values) Index name create table… video_rating varchar2(5) constraint dc_product_code references products(product_code)); SQL Table name and column name (provided the column has been defined as unique when the table was created) create table… seat_capacity smallint constraint ck_seat_capacity check (seat_capacity between 1 and 12)); SQL Index name Static values
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Physical Database Design: Denormalization Have 0..* 1..1 1..1 0..* Consist of Locate 1..* 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State 0..* Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1
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
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
Customers AAdvantage_number Customer_name Address Zip_code (fk) Itineraries Confirmation_number Itinerary_date AAdvantage_number (fk) Have 0..* 1..1 1..1 0..* Consist of Locate 1..* 1..1 Reservations Confirmation_number (fk) Airline_code (fk) Flight_number (fk) Flight_date Seat Class Zip_codes Zip_code City State 0..* Reserve 1..1 Flights Airline_code (fk) Flight_number Departure_time Arrival_time Origin Destination Food_service Movie Airlines Airline_code Airline Offer 0..* 1..1