Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Design Theory  Assess the quality of a schema  redundancy  integrity constraints  Quality seal: normal forms (1-4, BCNF)  Improve the quality.

Similar presentations


Presentation on theme: "Relational Design Theory  Assess the quality of a schema  redundancy  integrity constraints  Quality seal: normal forms (1-4, BCNF)  Improve the quality."— Presentation transcript:

1 Relational Design Theory  Assess the quality of a schema  redundancy  integrity constraints  Quality seal: normal forms (1-4, BCNF)  Improve the quality of a schema  synthesis algorithm  decomposition algorithm  Construct a (high-quality) schema  start with universal relation  apply synthesis or decomposition algorithms 1

2 What is wrong with redundancy?  Waste of storage space  importance is diminishing as storage gets cheaper  (disk density will even increase in the future)  Additional work to keep multiple copies of data consistent  multiple updates in order to accomodate one event  Additional code to keep multiple copies of data consistent  Somebody needs to implement the logic 2

3 Bad Schemas  Update-Anomaly  What happens when Sokrates moves to a different room?  Insert-Anomaly  What happens if Roscoe is elected as a new professor?  Delete-Anomaly  What happens if Popper does not teach this semester? ProfLecture PersNrNameLevelRoomNrTitleCP 2125SokratesFP2265041Ethik4 2125SokratesFP2265049Mäeutik2 2125SokratesFP2264052Logik4... 2132PopperAP525259Der Wiener Kreis2 2137KantFP74630Die 3 Kritiken4 3

4 Multi-version Databases  Storage becomes cheaper -> never throw anything away  It is more expensive to think about what to keep than simply to keep everything.  Consequence 1: No delete  Instead, set a status flag to „deleted“  No delete anomalies (only wasted storage)  Consequence 2: No update in place  Instead, create a new version of the tuple  No update anomalies (only wasted storage)  Insert anomalies still exist, but not a big problem  Result in multiple NULL values, but no inconsistencies  NoSQL Movement: Denormalized data (XML is great!) 4

5 Functional Dependencies  Schema: R = {A:D A, B:D B, C:D C, D:D D }  Instance: R  Let  R,  R   iff  r, s  R: r.  = s.   r.  = s.   (There is a function f: X D   X D  ) R ABCD a4b2c4d3 a1b1c1d1 a1b1c1d2 a2b2c3d2 a3b2c4d3 {A}  {B} {C, D }  {B} Not: {B}  {C} Convention: CD  B 5

6 Example Family Tree ChildFatherMotherGrandmaGrandpa SofieAlfonsSabineLotharLinde SofieAlfonsSabineHubertLisa NiklasAlfonsSabineLotharLinde NiklasAlfonsSabineHubertLisa... LotharMartha …………… 6

7 Example Family Tree ChildFatherMotherGrandmaGrandpa SofieAlfonsSabineLotharLinde SofieAlfonsSabineHubertLisa NiklasAlfonsSabineLotharLinde NiklasAlfonsSabineHubertLisa... LotharMartha ……………  Child  Father,Mother  Child, Grandpa  Grandma  Child, Grandma  Grandpa 7

8 Analogy to functions  f1 : Child  Father  E.g., f1(Niklas) = Alfons  f2: Child  Mother  E.g., f2(Niklas) = Sabine  f3: Child x Grandpa  Grandma  FD: Child  Father, Mother  represents two functions (f1, f2)  Komma on right side indicates multiple functions  FD: Child, Grandpa  Grandma  Komma on the left side indicates Cartesian product 8

9 Keys   R is a superkey iff   R   is minimal iff   A   (   Notation for minimal functional dependencies:      R is a key (or candidate key) iff     R 9

10 Determining Keys  Keys of Town  {Name, Canton}  {Name, AreaCode}  N.B. Two small towns may have the same area code. Town NameCantonAreaCodePopulation BuchsAG0816500 BuchsSG0718000 ZurichZH044300000 LausanneVD02160000... 10

11 Determining Functional Dependencies  Professor: {[PersNr, Name, Level, Room, City, Address, Zip, AreaCode, Canton, Population, Direktion]}  {PersNr}  {PersNr, Name, Level, Room, City, Address, Zip, AreaCode, Canton, Population, Direktion}  {City, Canton}  {Population, AreaCode}  {Zip}  {Canton, City, Population}  {Canton, City, Address}  {Zip}  {Canton}  {Direktion}  {Room}  {PersNr}  Additional functional dependencies (inferred):  {Room}  {PersNr, Name, Level, Room, City, Address, Zip, AreaCode, Canton, Population, Direktion}  {Zip}  {Direktion} 11

12 Visualization of Funct. Dependencies Direktion Level Name Address City Canton PersNr Room AreaCode Zip Population 12

13 Armstrong Axioms: Inference of FDs  Reflexivity  (   )    Special case:   Augmentation      (Notation  :=   Transitivity      .  These three axioms are complete. All possible other rules can be implied from these axioms. 13

14 Other rules  Union of FDs:       Decomposition:       Pseudo transitivity:      14

15 Correctness of Union rule  Premise:  and   Claim:   Proof:  (Premise)  (Augmentation)  (Premise)  (Augmentation)  (Transitivity of (4) and (2)) qed 15

16 Closure of Attributes  Input:  F: a set of FDs   : a set of attributes  Output:  + such that    + Closure(F,  ) result :=  // Reflexivity while (result has changed) do foreach FD:  in F do // Transitivity if   result then result := result   output(result)  Exercise: Proof that Closure is deterministic and terminates. 16

17 Example: Closure of ZIP (Slide 8) 17

18 Minimal Basis Fc is a minimal basis of F iff: 1.Fc  F  The closure of all attribute set is the same in Fc and F 2.All functional dependencies in Fc are minimal:   A   Fc - (  ((  Fc   B   Fc - (  (  Fc 3.In Fc, there are no two functional dependencies with the same left side.  Can be achieved by applying the Union rule. 18

19 Computing the Minimum Basis 1.Reduction of left sides of FDs. Let   F, A   : if  Closure(F,  – A) then replace  with (  - A)  in F 2.Reduction of right sides of FDs. Let   F, B   : if B  Closure(F – (  )  (  ),  ) then replace    with  –B) in F 1.Remove FDs:  (clean-up of Step 2) 2.Apply Union rule to FDs with the same left side. 19

20 Determining Functional Dependencies  Professor: {[PersNr, Name, Level, Room, City, Address, Zip, AreaCode, Canton, Population, Direktion]}  {PersNr}  {PersNr, Name, Level, Room, City, Address, Zip, AreaCode, Canton, Population, Direktion}  {City, Canton}  {Population, AreaCode}  {Zip}  {Canton, City, Population}  {Canton, City, Address}  {Zip}  {Canton}  {Direktion}  {Room}  {PersNr}  Additional functional dependencies (inferred):  {Room}  {PersNr, Name, Level, Room, City, Address, Zip, AreaCode, Canton, Population, Direktion}  {Zip}  {Direktion} 20

21 Correctness of the Algorithm (Left Reduction)  Premise:   Closure(F,  - A)  Claim:  Closure(F-{  }  (  - A) ,  - A)  Closure(F,  - A)  Proof: let   Closure(F-{  }  (  - A) ,  - A)   Closure(F,  - A  ) (Apply FD (  - A)  )   Closure(F,  - A) (Premise) qed 21

22 Bad Schemas  Update-Anomaly  What happens when Sokrates moves to a different room?  Insert-Anomaly  What happens if Roscoe is elected as a new professor?  Delete-Anomaly  What happens if Popper does not teach this semester? ProfLecture PersNrNameLevelRoomNrTitleCP 2125SokratesFP2265041Ethik4 2125SokratesFP2265049Mäeutik2 2125SokratesFP2264052Logik4... 2132PopperAP525259Der Wiener Kreis2 2137KantFP74630Die 3 Kritiken4 22

23 Decomposition of Relations  Bad relations combine several concepts  decompose them so that each concept in one relation  R  R 1,.., R n 1.Lossless Decomposition R =  R 1 A R 2 A... A R n 2.Preservation of Dependencies  FD( R )+ = (FD( R 1 ) ...  FD( R n ))+ 23

24 When is a decomposition lossless?  Let R = R 1  R 2  R1 := Π R 1 (R)  R2 := Π R 2 (R)  Lemma: The decomposition is lossless if  ( R 1  R 2)  R 1 or  ( R 1  R 2)  R 2  Exercise: Proof of this Lemma. R R 1   R 2  24

25 Example Drinker PubGuestBeer KowalskiKemperPils KowalskiEicklerHefeweizen InnstegKemperHefeweizen 25

26 Lossy Decomposition Drinker PubGuestBeer KowalskiKemperPils KowalskiEicklerHefeweizen InnstegKemperHefeweizen Visitor PubGuest KowalskiKemper KowalskiEickler InnstegKemper Drinks GuestBeer KemperPils EicklerHefeweizen KemperHefeweizen  Guest, Beer  Pub, Guest 26

27 Drinker KneipeGastBier KowalskiKemperPils KowalskiEicklerHefeweizen InnstegKemperHefeweizen Visitor PubGuest KowalskiKemper KowalskiEickler InnstegKemper Drinks GuestBeer KemperPils EicklerHefeweizen KemperHefeweizen .... VisitorA Drinks PubGuestBeer KowalskiKemperPils KowalskiKemperHefeweizen KowalskiEicklerHefeweizen InnstegKemperPils InnstegKemperHefeweizen A ≠ 27

28 Comments on the Example  Drinker has one (non-trivial) functional dependency  {Pub,Guest}  {Beer}  But none of the criteria of the Lemma hold  {Guest}  {Beer}  {Guest}  {Pub}  The problem is that Kemper likes different beer in different pubs. 28

29 Lossless Decomposition Parents FatherMotherChild JohannMarthaElse JohannMariaTheo HeinzMarthaCleo Father Child JohannElse JohannTheo HeinzCleo Mother Child MarthaElse MariaTheo MarthaCleo  Mother, Child  Father, Child 29

30 Comments on Example  Parents: {[Father, Mother, Child]}  Father: {[Father, Child]}  Mother: {[Mother, Child]}  Actually, both criteria of the lemma are met:  {Child}  {Mother}  {Child}  {Father}  {Child} is a key of all three relations  Wrt loss of info, it never hurts to decompose with a key  However, it is never beneficial either. Why? 30

31 Preservation of Dependencies  Let R be decomposed into R 1,..., R n  F R = (F R 1 ...  F R n )  ZipCodes: {[Street, City, Canton, Zip]}  Functional dependencies in ZipCodes  {Zip}  {City, Canton}  {Street, City, Canton}  {Zip}  What about this decomposition?  Streets: {[Zip, Street]}  Cities: {[Zip, City, Canton]}  Is it lossless? Does it preserve functional depend.? 31

32 Decomposition of ZipCodes ZipCodes CityCantonStreetZip BuchsAGGoethestr.5033 BuchsAGSchillerstr.5034 BuchsSGGoethestr.8107 Streets ZipStreet 8107Goethestr. 5033Goethestr. 5034Schillerstr. Cities CityCantonZip BuchsAG5033 BuchsAG5034 BuchsSG8107  City,Canton,Zip  Zip,Street {Street, City, Canton}  {Zip} not checkable in decomp. schema It is possible to insert inconsistent tuples 32

33 Violation of City,Canton,Street  Zip ZipCodes CityCantonStreetZip BuchsAGGoethestr.5033 BuchsAGSchillerstr.5034 BuchsSGGoethestr.8107 Streets ZipStreet 8107Goethestr. 5033Goethestr. 5034Schillerstr. 8108Goethestr. Cities CityCantonZip BuchsAG5033 BuchsAG5034 BuchsSG8107 BuchsSG8108  City,Canton,Zip  Zip,Street 33

34 Violation of City,Canton,Street  Zip ZipCodes CityCantonStreetZip BuchsAGGoethestr.5033 BuchsAGSchillerstr.5034 BuchsSGGoethestr.8107 BuchsSGGoethestr.8108 Streets ZipStreet 8107Goethestr. 5033Goethestr. 5034Schillerstr. 8108Goethestr. Cities CityCantionZip BuchsAG5033 BuchsAG5034 BuchsSG8107 BuchsSG8108 A 34

35 First Normal Form  Only atomic domains (as in SQL 92) vs. Parents FatherMotherChildren JohannMartha{Else, Lucie} JohannMaria{Theo, Josef} HeinzMartha{Cleo} Parents FatherMotherChild JohannMarthaElse JohannMarthaLucie JohannMariaTheo JohannMariaJosef HeinzMarthaCleo 35

36 Second Normal Form  R is in 2NF iff every non-key attribute is minimally dependent on every key.  StudentAttends is not in 2NF!!!  {Legi}  {Name, Semester} StundentAttends LegiNrNameSemester 261205001Fichte10 275505001Schopenhauer6 275504052Schopenhauer6 281065041Carnap3 281065052Carnap3 281065216Carnap3 281065259Carnap3... 36

37 Second Normal Form  Insert Anomaly: What about students who attend no lecture?  Update Anomaly: Promotion of Carnab to the 4th semester.  Delete Anomaly: Fichte drops his last course?  Solution: Decompose into two relations  attends: {[Legi, Nr]}  Student: {[Legi, Name, Semester]}  Student, attends are in 2NF. The decompostion is lossless and preserves dependencies. Legi Nr Name Semester 37

38 2NF and ER Modelling  Violation of 2NF  mixing an entity with an N:M (or 1:N) relationship  E.g., mixing Student (entity) with attends (N:M)  Solution  Separate: entity and relationship  i.e., implement entity and relationship in separate relations  However, okay to mix entity and 1:1/N:1 relationship Professor Lecture gives 1 N Not okay Okay 38

39 Third Normal Form  R is in 3NF iff for all  in R at least one condition holds:  B   (i.e.,  is trivial)   is an attribute of at least one key   is a superkey of R  If  does not fulfill any of these conditions   is a concept in its own right. 39

40 Example: 2NF but not 3NF Direktion Level Name Address City Canton PersNr Room AreaCode Zip Population 40

41 3NF and ER Modelling  Violation of 3NF  mixing several entities (maybe connected by relationships)  e.g., Professor, City, Canton  Solution  implement each entity in a separate relation  (implement N:M relationships in separate relation)  ER Modelling and Rules of ER -> relational  Automatically create 3NF Professor City lives 1 N Canton 1 belongs N Okay Not okay 41

42 3NF implies 2NF  Premise: R is in 3NF  Claim: R is in 2NF  Proof:  assume R is not in 2NF  By definition of 2NF: exists  such that  (1) B is not part of any key  (2)   is a key   is evil  it is not trivial (otherwise B would be part of a key)  B is not part of any key (1)   is not a superkey (2)  R is not in 3NF. qed 42

43 Synthesis Algorithm  Input: Relation R, FDs F  Output: R 1,..., R n such that  R 1,..., R n is a lossless decomposition of R.  R 1,..., R n preserves dependencies.  All R 1,..., R n are in 3NF. 43

44 Synthesis Algorithm 1.Compute the minimal basis Fc of F. 2.For all   Fc create:  R  :=   3.If exists   R such that  is a key of R create:  R   (N.B.: R  has no non-trivial functional dependencies.) 4.Eliminate R  if exists R  ` such that:  R  R  ` 44

45 Example: Synthesis Algorithm  Professor: {[PersNr, Name, Level, Room, City, Street, Zip, AreaCode, Canton, Population, Direktion]} 1.{PersNr}  {Name, Level, Room, Canton, Street, Canton} 2.{Room}  {PersNr} 3.{Street, Canton, City}  {Zip} 4.{City, Canton}  {Population, AreaCode} 5.{Canton}  {Direktion} 6.{Zip}  {Canton, City}  Professor: {[PersNr, Name, Level, Room, City, Street, Canton]}  ZipCodes: {[Street, Canton, City, Zip]}  Cities: {[City, Canton, Population, AreaCode]}  Administration: {[Canton, Direktion]} 45

46 Example why Step 3 is needed  StudentAttends(Legi, Nr, Name, Semester)  Minimum Basis (Step 1)  {Legi}  {Name, Semester}  Relation generated from minimum basis (Step 2)  Student(Legi, Name, Semester)  Relation generated from Step 3  attends(Legi, Nr)  The attends relation is needed! 46

47 Corner Case: Step 3  R(A, B, C, D)  B -> C, D  D -> B  Keys of R  A, B  A, D  Decomposition into 3NF (Synthesis Algorithm)  R1(B, C, D)  R2(A, B)  N.B. R3(A,D) is not needed!!!  Needs to be cleaned up in Step 4! 47

48 ZipCodes(Street, Canton, City, Zip)  Is ZipCodes in 3NF?  Keys: {Street,Canton,City}, {Zip,Street}  All attributes are part of keys. There are no evil FDs!  Does the decomposition preserve dependencies?  Yes!  Is the decomposition lossless?  Professor  ZipCodes = {Street,Canton,City}  {Street,Canton,City}  ZipCodes  Criterion of Lemma is fullfilled!  Is ZipCode free of redundancy? 48

49 Exercises  Proof for the following lemmas:  The synthesis algorithm preserves dependencies.  The synthesis algorithm creates lossless decompositions.  The synthesis algorithm creates relations in 3NF only.  The synthesis algorithm creates relations in 2NF only. 49

50 Synthesis Algo produces 3NF only  Let R i be a relation created by the Synthesis Algo  Case 1: R i was created in Step 3 of the algo  R i contains a key of R  there are no non-trivial FDs in R i  R i is in 3NF  Case 2: R i was created in Step 2 by an FD:   (1) R i :=    (2)  is a key of R i   is minimal because of left reduction of minimal basis   R i by construction of R i  (3)  is not evil because  is a superkey of R i  (4) Let  be any other non-trivial FD (  )   because of right reduction in minimal basis and because    contains only attributes of a key;  is not evil qed 50

51 Boyce-Codd-Normal Form (BCNF )  R is in BCNF iff for all  in R at least one condition holds:  B   (i.e.,  is trivial)   is a superkey of R  R in BCNF implies R in 3NF  Proof trivial from definition  Result  any schema can be decomposed losslessly into BCNF  but, preservation of dependencies cannot be guaranteed  need to trade „correctness“ for „efficiency“  that is why 3NF is so important in practice 51

52 ZipCodes(Street, Canton, City, Zip)  ZipCodes is not in BCNF  {Zip}  {Canton, City} // evil  {Street, Canton, City}  {Zip} // okay  Redundancy in ZipCodes  (Rämistr., Zürich, Zürich, 8006)  (Universitätsstr., Zürich, Zürich, 8006)  (Schmid-Str., Zürich, Zürich, 8006)  stores several times that 8006 belongs to Zürich  Exercise: How would you model ZipCodes in ER?  What would the relational schema look like? 52

53 Decomposition Algorithm (BCNF)  Input: R  Output: R 1,..., R n such that  R 1,..., R n is a lossless decomposition of R.  R 1,..., R n are in BCNF.  (Preservation of dependencies is not guaranteed.) 53

54 Decomposition Algorithm  Input: R  Output: R 1,..., R n result = { R } while (  R i  Z: R i is not in BCNF )) let  be evil in R i R i1 =  R i2 = R i -  result = (result – { R i})  { R i1}  { R i2} output(result) 54

55 Visualization of Decomposition Algo RiRi R i 1   R i 2  R i –(  ) 55

56 Decomposition of ZipCodes  ZipCodes: {[Street, City, Canton, Zip]}  {Zip}  {City, Canton}// evil  {Street, City, Canton}  {Zip}// okay  Applying the decomposition algorithm...  Street: {[Zip, Street]}  Cities: {[Zip, City, Canton]}  Assessment  decomposition is lossless  decomposition does not preserve dependencies 56

57 Cities is not in BCNF  Cities: {[City, Canton, Direktion, Population]}  FDs of Cities:  {City, Canton}  {Population}  {Canton}  {Direktion}  {Direktion}  {Canton}  Keys:  {City, Canton}  In which highest NF is Cities?  N.B. decomposition algo can also be applied to non 3NF! KölnNRWRütgers1mio BonnNRWRütgers200K AachenNRWRütgers200K 57

58 Decomposition of Cities  Cities: {[City, Canton, Direktion, Population]}  {Canton}  {Direktion} // evil  {Direktion}  {Canton} // evil  {City, Canton}  {Population} // okay  R i 1:  Administration: {[Canton, Direktion]}  R i 2:  Cities: {[City, Canton, Population]}  Is this decomposition lossless? Preserves depend.? 58

59 Fourth Normal Form  Give FDs, keys. Which highest normal form?  Does „Skills“ have redundancy?  What happens if 3002 learns a new language?  How would you model Skills in ER? How translated? Skills PersNrLanguageProgramming 3002GreekC 3002LatinPascal 3002GreekPascal 3002LatinC 3005GermanAda 59

60 NFNF  This model would work: no redundancy, no anomolies  But, unfortunately, not implementable in SQL 2  It is implementable in SQL 3 and XML  That is why design theory needs to be adapted to XML Skills PersNrLanguageProgramming 3002{Greek, Latin}{C, Pascal} 3005{German}{Ada} 60

61 What is wrong with this?  Who knows Greek and Pascal?  Anomolies?  What happens if 3002 learns a new language? Skills PersNrLanguageProgramming 3002GreekC 3002LatinPascal 3005GermanAda 61

62 Multi-value Dependencies  A  B  A  C R ABC abc abbcc abbc abcc 62

63 Multi-value Dependencies (MVD)     iff   t1, t2  R: t1.  = t2.   t3, t4  R:  t3.  = t4.  = t1.  = t2.   t3.  = t1.  t4.  = t2.   t3.  = t2.  t4.  = t1.  R  A1... Ai  Ai+1... Aj  Aj+1... An a1... aiai+1... ajaj+1... an a1... aibi+1... bjbj+1... bn a1... aibi+1... bjaj+1... an a1... aiai+1... ajbj+1... bn 63

64 MVD: Example  MVDs of Skills  {PersNr}  {Language}  {PersNr}  {Programming}  {Language} {PersNr, Programming} (???)  MVDs can result in anomalies and redundancy Skills PersNrLanguageProgramming 3002GreekC 3002LatinPascal 3002GreekPascal 3002LatinC 3005GermanAda 64

65 Are MVDs symmetric?  NO!  NOT {Language}  {PersNr}  Exercise: Find examples for symmetric MVDs! Skills PersNrLanguageProgramming 3002GreekC 3002LatinPascal 3002GreekPascal 3002LatinC 3005GermanAda 3007GreekXQuery 65

66 MVD: Example Skills PersNrLanguageProgramming 3002GreekC 3002LatinPascal 3002GreekPascal 3002LatinC 3005GermanAda Language PersNrLanguage 3002Greek 3002Latin 3005German Programming PersNrProgramming 3002C Pascal 3005Ada  PersNr, Language  PersNr, Programming 66

67 MVD: Example Skills PersNrLanguageProgramming 3002GreekC 3002LatinPascal 3002GreekPascal 3002LatinC 3005GermanAda Language PersNrLanguage 3002Greek 3002Latin 3005German Programming PersNrProgramming 3002C Pascal 3005Ada JoinA 67

68 Example: Drinkers  drinkers: {[name, addr, phones, beersLiked]}  some people have several phones  some people like several kind of beers  FDs and MVDs  name  addr  name  phones  name  beersLiked  Again, MVDs indicate redundancy  phones and beersLiked are independent concepts  (Would work if you could store them as sets: NFNF.) 68

69  Let R = R 1  R 2  R1 := Π R 1 (R)  R2 := Π R 2 (R)  Lemma: The decomposition is lossless iff  ( R 1  R 2)  R 1 or  ( R 1  R 2)  R 2  Exercise: Proof of this Lemma. Which direction is easier? R R 1   R 2  Lossless Decompositions with MVDs 69

70 Laws of MVDs  Trivial MVDs:   R  Check criterion of MVDs (  = R,  )   t1, t2  R: t1.  = t2.   t3, t4  R:  t3.  = t4.  = t1.  = t2.   t3.  = t1.  t4.  = t2.   t3.  = t2.  t4.  = t1.   let t1, t2  R: t1.  = t2.   set t3=t1, t4=t2  t3.  = t4.  = t1.  = t2.  (by def. of t3, t4)  t3.  = t1.  (by def. of t3)  t4.  = t2.  (by def. of t4)  t3.  = t2.  (  )  t4.  = t1.  (  )qed  Adapt proof for:   R -  70

71 Laws of MVDs  Promotion:     let t1, t2  R: t1.  = t2.   (1) t1.  = t2.  (  )  set t3=t2, t4=t1  t3.  = t4.  = t1.  = t2.  (by def. of t3, t4)  t3.  = t1.  (1)  t4.  = t2.  (1)  t3.  = t2.  (by def. of t3)  t4.  = t1.  (by def. of t4) qed     does not always hold!  e.g., PersNr  Language, but PersNr  Language 71

72 Laws of MVDs  Reflexivity: (   )    Augmentation:     Transitivity:       Complement:    R   Multi-value Augmentation:   (     Multi-value Transitivity:       Generalization (Promotion):    72

73 Laws of MVDs (ctd.)  Coalesce:   (   )  (  =  )      Multi-value Union:     Intersection:     Minus:    –    Warning: NOT (     Not all rules of FDs apply to MVDs!  Exercise: find an example for which this law does not hold 73

74 WARNING  NOT (     Not all rules of FDs apply to MVDs!  E.g., {Language}  {PersNr, Programming}  But, NOT {Language}  {PersNr}  And NOT {Language}  {Programming}  Be careful with MVDs  Not a totally intuitive concept 74

75 Trivial MVDs     is trivial iff     or   = R -   Proof: a trivial MVD holds for any relation. 75

76 Fourth Normal Form (4NF )  R is in 4NF iff for all    at least one condition holds:     is trivial   is a superkey of R  R in 4NF implies R in BCNF  Proof is based on       .  (Can you prove that?) 76

77 Decomposition Algorithm for 4NF  Input: R  Output: R 1,..., R n result = { R } while (  R i  Z: R i is not in 4NF )) let    be evil in R i R i1 =  R i2 = R i -  result = (result – { R i})  { R i1}  { R i2} output(result) 77

78 Decomposition into 4 NF 78

79 Example  Assistant: {[PersNr, Name, Area, Boss, Language, Progr.]}  Synthesis Algorithm (3NF)  Assistant: {[PersNr, Name, Area, Boss]}  Skills: {[PersNr, Language, Programming]}  Decomposition Algorithm (4NF)  Assistant: {[PersNr, Name, Area, Boss]}  Languages: {[PersNr, Language]}  Programming: {[PersNr, Programming]} 79

80 Summary  Lossless decomposition up to 4NF  Preserving dependencies up to 3NF (implementable in SQL92) Synthesis Algorithm Decomposition Algorithm lossless & preserv. dep. lossless 80

81 Exercise  Find FDs, MVDs, keys  Decompose into 3NF, BCNF, 4NF Family Tree ChildFatherMotherGrandpaGrandma SofieAlfonsSabineLotharLinde SofieAlfonsSabineHubertLisa NiklasAlfonsSabineLotharLinde NiklasAlfonsSabineHubertLisa TobiasLeoBerthaHubertMartha …………… 81

82 Exercise: 1:N & N:M Relationships R AB S CD T EF V GH 1 N N M N M UR: {[ A, B, C, D, E, F, G, H ]} 82


Download ppt "Relational Design Theory  Assess the quality of a schema  redundancy  integrity constraints  Quality seal: normal forms (1-4, BCNF)  Improve the quality."

Similar presentations


Ads by Google