# dependency preserving

Post on 24-Apr-2015

250 views

Embed Size (px)

DESCRIPTION

TRANSCRIPT

- 1. Dependency Preserving Decomposition DAVID DENG CS157B MARCH 23, 2010
- 2. IntroDecomposition help us eliminate redundancy, root of data anomalies.Decomposition should be: 1. Lossless 2. Dependency Preserving
- 3. Whats Dependency Preservation?When the decomposition of a relational scheme preserved the associated set of functional dependencies.Formal Definition:If R is decomposed into R1, R2,, Rn, then{F1F2Fn}+ = F+
- 4. Algorithm to check for Dependency Preservationbegin;for each X Y in F and with R (R1, R2, , Rn){ let Z = X; while there are changes in Z { from i=1 to n Z = Z ((Z Ri)+ Ri) w.r.t to F; } if Y is a proper subset of Z, current fd is preserved else decomposition is not dependency preserving;}this is a dependency preserving decomposition;end;
- 5. Explain Algorithm Part 11. Choose a functional dependency in set F, say you choose X Y.2. Let set Z to the left hand side of the functional dependency, X such Z = XStarting with R1 in the decomposed set {R1, R2,Rn)3. Intersect Z with R1, Z R14. Find the closure of the result from step 3 (Z R1) using original set F5. Intersect the result from step 4 ((Z R1)+) with R1 again.
- 6. Explain Algorithm Part 26. Updated Z with new attribute in the result from step 5.7. Repeat step 3-6 from R2, R3, , Rn.8. If theres any changes between original Z before step 3 and after step 7, repeat step 3-7.9. Check whether Y is a proper subset of current Z. If it is not, this decomposition is a violation of dependency preservation. You can stop now.10. If Y is a proper subset of current Z, repeat 1-9 until you check ALL functional dependencies in set F.
- 7. Another look at AlgorithmTest each X Y in F for dependency preservationresult = Xwhile (changes to result) do for each Ri in decomposition t = (result Ri)+ Ri result = result tif Y result, return true;else, return false;[Note: If any false is returned for algorithm, whole decomposition is not dependency preserving.]
- 8. Lets walk through an example of using this algorithm.
- 9. Example using AlgorithmGiven the following:R(A,B,C,D,E)F = {ABC, CE, BD, EA}R1(B,C,D) R2(A,C,E)Is this decomposition dependency preserving?
- 10. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=ABFor Z R1 = AB BCD = B {B}+ = BD {B}+ R1 = BD BCD = BDUpdate Z = AB BD = ABD, continue
- 11. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=ABDFor Z R2 = ABD ACE = A {A}+ = A {A}+ R2 = A ACE = AUpdate Z, Z is still ABDSince Z changed, repeat checking R1 to R2.
- 12. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=ABDFor Z R1 = ABD BCD = BD {BD}+ = BD {BD}+ R1 = BD BCD = BDUpdate Z = ABD BD = ABD, so Z hasntchanged but you still have to continue.
- 13. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=ABD and checking R2 was done 2 slides agoZ will still be ABD.Since Z hasnt change, you can conclude ABCis not preserved.Lets practice with other functionaldependencies.
- 14. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=X=BFor Z R1 = B BCD = B {B}+ = BD {B}+ R1 = BD BCD = BDUpdate Z = B BD = BDSince Y=D is proper subset of BD, BD ispreserved.
- 15. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=X=CFor Z R2 = C ACE = C {C}+ = CEA {C}+ R1 = CEA ACE = ACEUpdate Z = C ACE= ACESince Y=E is proper subset of ACE, CE ispreserved.
- 16. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Z=X=EFor Z R1 = E ACE = E {E}+ = EA {E}+ R1 = EA ACE = EAUpdate Z = E EA= EASince Y=A is proper subset of EA, EA ispreserved.
- 17. ExampleR(A,B,C,D,E) F = {ABC, CE, BD, EA}Decomposition: R1(B,C,D) R2(A,C,E)Shortcut:For any functional dependency, if both LHS and RHS collectively are within any of the sub scheme Ri. Then this functional dependency is preserved.
- 18. Exercise #1Let R{A,B,C,D}andF={AB, BC, CD, DA}Lets decomposed R into R1 = AB, R2 = BC, and R3 = CDIs this a dependency preserving decomposition?
- 19. Answer to Exercise #1R{A,B,C,D} F={AB, BC, CD, DA}Decomposition: R1 = AB, R2 = BC, and R3 = CDYes it is.You can immediately see that AB, BC, CD are preserved for R1, R2, R3The key is to check whether DA is preserved.Lets walk through the algorithm.
- 20. Answer to Exercise #1R{A,B,C,D} F={AB, BC, CD, DA}Decomposition: R1 = AB, R2 = BC, and R3 = CDZ=X=DFor Z R1 = D AB = empty setFor Z R2 = D BC = empty setFor Z R3 = D CD = D Find {D}+ = DABC Find {D}+ R3 = DABC CD = CDUpdate Z to CD. Since Z changed, repeat.
- 21. Answer to Exercise #1R{A,B,C,D} F={AB, BC, CD, DA}Decomposition: R1 = AB, R2 = BC, and R3 = CDZ = CDFor Z R1 = CD AB = empty setFor Z R2 = CD BC = C Find {C}+ = CDAB Find {C}+ R2 = CDAB BC = BCUpdate Z = CD BC = BCD
- 22. Answer to Exercise #1R{A,B,C,D} F={AB, BC, CD, DA}Decomposition: R1 = AB, R2 = BC, and R3 = CDZ = BCDFor Z R3 = BCD CD = CD Find {CD}+ = CDAB Find {CD}+ R3 = CDAB CD = CDUpdate Z is still BCD. Since Z changed, repeat going trough R1 to R3.
- 23. Answer to Exercise #1R{A,B,C,D} F={AB, BC, CD, DA}Decomposition: R1 = AB, R2 = BC, and R3 = CDZ = BCDFor Z R1 = BCD AB = B Find {B}+ = BCDA Find {B}+ R1 = BCDA AB = ABUpdate Z = BCD AB = ABCD.Since Y = A is a subset of ABCD, function DA is preserved.
- 24. Exercise #2R{A,B,C,D,E)F={ABD, BE}Decomposition:R1{A,B,C} R2{A,D} R3{B,D,E}Is this a dependency preserving decomposition?
- 25. Answer to Exercise #2R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,C} R2{A,D} R3{B,D,E}Lets start with ABD:Z=AZ R1 = A ABC = A {A}+ = ABDE {A}+ R1 = ABDE ABC = ABUpdate Z = A AB = AB
- 26. Answer to Exercise #2R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,C} R2{A,D} R3{B,D,E}Z = ABZ R2 = A AD = A {A}+ = ABDE {A}+ R1 = ABDE AD = ADUpdate Z = AB AD = ABDThus A BD preserved
- 27. Answer to Exercise #2R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,

Recommended

View more >