Presentation is loading. Please wait.

Presentation is loading. Please wait.

More on Decompositions and Third Normal Form CIS 4301 Lecture Notes Lecture 11 - 2/16/2006.

Similar presentations


Presentation on theme: "More on Decompositions and Third Normal Form CIS 4301 Lecture Notes Lecture 11 - 2/16/2006."— Presentation transcript:

1 More on Decompositions and Third Normal Form CIS 4301 Lecture Notes Lecture 11 - 2/16/2006

2 Lecture 11© CIS 4301 - Spring 20062 Recovering Information Idea behind decomposition is that we can “join” two relations and get original data back Lossless join preservation What can go wrong? May not get all of the original tuples back May get “new” tuples which were not part of the original relation In both cases, loss of information Let’s find out why decomposition works

3 Lecture 11© CIS 4301 - Spring 20063 Recovering Information R(A,B,C) FD: {B  C} is a BCNF violation Decomposition: R 1 (A,B) and R 2 (B,C) What are our options for keys? R 1 : A or A,B R 2 : B,C Does this decomposition allows us to recover all of (and only) the tuples of R?

4 Lecture 11© CIS 4301 - Spring 20064 Test 1: Do We Get All Tuples Back? Let t be tuple of R: t=(a,b,c ) t projects as t 1 = (a,b) for R 1 t projects as t 2 = (b,c) for R 2 Since t 1 and t 2 agree on b value, it is always possible to get t = t 1 join t 2

5 Lecture 11© CIS 4301 - Spring 20065 Test 2: Do We Get Only Tuples from R Back? What happens if we join R1 and R2? x= (a,b,e) Is x a tuple of R? YES! Since B  C holds. Why? abc dbe R t v ab R1R1 t be R2R2 v

6 Lecture 11© CIS 4301 - Spring 20066 Third Normal Form (3NF) Occasionally, we encounter a relation and its dependencies that are not in BCNF but that one doesn’t want to decompose any further Ex.: Bookings(title,theater,city) (m,t,c) : movie with title m is currently being shown at theater t in city c FDs: theater  city title city  theater What are the candidate key(s) for Bookings ? Use augment. rule on theater  city to get theater,title  city,title Use augment. rule on title,city  theater to get title,city  theater,city,title {title, city} {theater, title}

7 Lecture 11© CIS 4301 - Spring 20067 Decomposition with Problems FD: theater  city is a violation, theater is not a superkey theatercity R1 GuildMenlo Park ParkMenlo Park theatertitle R2 GuildThe Net ParkThe Net Tempted to decompose Bookings into R1(theater,city) F1: {theater  city} R2(theater,title) F2: {only trivial} Problem! What happened to original FD title city  theater ? permissible snapshots

8 Lecture 11© CIS 4301 - Spring 20068 Joined Bookings Violates FD In the joined relation, the tuples violate the FD title city  theater theatercity R1 GuildMenlo Park ParkMenlo Park theatertitle R2 GuildThe Net ParkThe Net theatertitle R1R2 GuildThe Net ParkThe Net city Menlo Park

9 Lecture 11© CIS 4301 - Spring 20069 Solution Relax our definition of BCNF slightly allow occasional relational schema that cannot be decomposed further without losing the ability to check each FD within one relation Relaxed condition is called 3NF Definition: A relation is in 3NF if: whenever A 1 A 2 … A n  B is a nontrivial dependency, either {A 1, A 2, …, A n } is a superkey, or B is a member of some key Original Bookings in 3NF

10 Lecture 11© CIS 4301 - Spring 200610 Summary What’s so great about 3NF? We can always decompose a a relation schema in a way that does not lose information, into schemas that are in 3NF In addition: allow ALL functional dependencies to be checked! HOWEVER: when these relations are left in 3NF (not in BCNF), there will be some redundancy left in schema

11 Lecture 11© CIS 4301 - Spring 200611 Multivalued Dependencies There are schemas that are in BCNF that do not seem to be sufficiently normalized namestreet Stars citytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. 123 Maple Str. 5 Locust Ln. 123 Maple Str. 5 Locust Ln.C. Fisher Hollywood Malibu Hollywood Malibu Hollywood Malibu Star Wars1977 Star Wars1977 Empire Strikes Back1980 Empire Strikes Back1980 Return of the Jedi1983 Return of the Jedi1983

12 Lecture 11© CIS 4301 - Spring 200612 Attribute Independence No reason to associate address with one movie and not another When we repeat address and movie facts in all combinations, there is obvious redundancy However, NO BCNF violation in Stars relation There are no non-trivial FD’s at all, all five attributes form the only superkey Why?

13 Lecture 11© CIS 4301 - Spring 200613 Definition Definition: Multivalued dependency (MVD): A 1 A 2 …A n  B 1 B 2 …B m holds for relation R if: For all tuples t, u in R If t[A 1 A 2...A n ] = u[A 1 A 2...A n ], then there exists a v in R such that: (1) v[A 1 A 2...A n ] = t[A 1 A 2...A n ] = u[A 1 A 2...A n ] (2) v[B 1 B 2 …B m ] = t[B 1 B 2 …B m ] (3) v[C 1 C 2 …C k ] = u[C 1 C 2 …C k ], where C 1 C 2 …C k is all attributes in R except (A 1 A 2...A n  B 1 B 2 …B m )

14 Lecture 11© CIS 4301 - Spring 200614 Pictorially Speaking... An MVD guarantees v exists The existence of a fourth tuple w is implied by interchanging t and u t u A’sB’sOthers v w

15 Lecture 11© CIS 4301 - Spring 200615 Example: name  street city namestreet Stars citytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. Hollywood Malibu Star Wars1977 Empire Strikes Back1980 Empire Strikes Back1980 C. Fisher 5 Locust Ln. 123 Maple Str. 5 Locust Ln.C. Fisher Malibu Hollywood Malibu Star Wars1977 Return of the Jedi1983 Return of the Jedi1983 t u v

16 Lecture 11© CIS 4301 - Spring 200616 Example: name  street city namestreet Stars citytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. 123 Maple Str. 5 Locust Ln. Hollywood Malibu Hollywood Malibu Star Wars1977 Star Wars1977 Empire Strikes Back1980 Empire Strikes Back1980 C. Fisher123 Maple Str. 5 Locust Ln.C. Fisher Hollywood Malibu Return of the Jedi1983 Return of the Jedi1983 u t w v


Download ppt "More on Decompositions and Third Normal Form CIS 4301 Lecture Notes Lecture 11 - 2/16/2006."

Similar presentations


Ads by Google