29
DAVID DENG CS157B MARCH 23, 2010 Dependency Preserving Decomposition

Dependency preserving

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Dependency preserving

DAVID DENG

CS157BMARCH 23, 2010

Dependency Preserving Decomposition

Page 2: Dependency preserving

Intro

Decomposition help us eliminate redundancy, root of data anomalies.

Decomposition should be: 1. Lossless 2. Dependency Preserving

Page 3: Dependency preserving

What’s 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{F1F2…Fn}+ = F+

Page 4: Dependency preserving

Algorithm to check for Dependency Preservation

begin;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 nZ = Z ((Z Ri)+ Ri) w.r.t to F;

}if Y is a proper subset of Z, current fd is preservedelse decomposition is not dependency preserving;

}this is a dependency preserving decomposition;end;

Page 5: Dependency preserving

Explain Algorithm Part 1

1. 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 = X

 Starting 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.

Page 6: Dependency preserving

Explain Algorithm Part 2

6. Updated Z with new attribute in the result from step 5.

7. Repeat step 3-6 from R2, R3, …, Rn.8. If there’s 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.

Page 7: Dependency preserving

Another look at Algorithm

Test each X Y in F for dependency preservation

result = Xwhile (changes to result) do

for each Ri in decompositiont = (result Ri)+ Riresult = result t

if Y result, return true;else, return false;

[Note: If any false is returned for algorithm, whole decomposition is not dependency preserving.]

Page 8: Dependency preserving

Let’s walk through an example of using this algorithm.

Page 9: Dependency preserving

Example using Algorithm

Given 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?

Page 10: Dependency preserving

Example

R(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 = BD

Update Z = AB BD = ABD, continue

Page 11: Dependency preserving

Example

R(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 = A

Update Z, Z is still ABD Since Z changed, repeat checking R1 to R2.

Page 12: Dependency preserving

Example

R(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 = BD

Update Z = ABD BD = ABD, so Z hasn’t changed but you still have to continue.

Page 13: Dependency preserving

Example

R(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 hasn’t change, you can conclude ABC is not preserved.

Let’s practice with other functional dependencies.

Page 14: Dependency preserving

Example

R(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 = BD

Update Z = B BD = BDSince Y=D is proper subset of BD, BD is preserved.

Page 15: Dependency preserving

Example

R(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 = ACE

Update Z = C ACE= ACESince Y=E is proper subset of ACE, CE is preserved.

Page 16: Dependency preserving

Example

R(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 = EA

Update Z = E EA= EASince Y=A is proper subset of EA, EA is preserved.

Page 17: Dependency preserving

Example

R(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.

Page 18: Dependency preserving

Exercise #1

Let R{A,B,C,D} and F={AB, BC, CD, DA}

Let’s decomposed R into R1 = AB, R2 = BC, and R3 = CD

Is this a dependency preserving decomposition?

Page 19: Dependency preserving

Answer to Exercise #1

Yes it is.You can immediately see that AB, BC,

CD are preserved for R1, R2, R3The key is to check whether DA is

preserved.Let’s walk through the algorithm.

R{A,B,C,D} F={AB, BC, CD, DA}

Decomposition: R1 = AB, R2 = BC, and R3 = CD

Page 20: Dependency preserving

Answer to Exercise #1

Z = X = DFor Z R1 = D AB = empty setFor Z R2 = D BC = empty setFor Z R3 = D CD = D

Find {D}+ = DABCFind {D}+ R3 = DABC CD = CD

Update Z to CD. Since Z changed, repeat.

R{A,B,C,D} F={AB, BC, CD, DA}

Decomposition: R1 = AB, R2 = BC, and R3 = CD

Page 21: Dependency preserving

Answer to Exercise #1

Z = CDFor Z R1 = CD AB = empty setFor Z R2 = CD BC = C

Find {C}+ = CDABFind {C}+ R2 = CDAB BC = BC

Update Z = CD BC = BCD

R{A,B,C,D} F={AB, BC, CD, DA}

Decomposition: R1 = AB, R2 = BC, and R3 = CD

Page 22: Dependency preserving

Answer to Exercise #1

Z = BCDFor Z R3 = BCD CD = CD

Find {CD}+ = CDABFind {CD}+ R3 = CDAB CD = CD

Update Z is still BCD. Since Z changed, repeat going trough R1 to R3.

R{A,B,C,D} F={AB, BC, CD, DA}

Decomposition: R1 = AB, R2 = BC, and R3 = CD

Page 23: Dependency preserving

Answer to Exercise #1

Z = BCDFor Z R1 = BCD AB = B

Find {B}+ = BCDAFind {B}+ R1 = BCDA AB = AB

Update Z = BCD AB = ABCD. Since Y = A is a subset of ABCD, function

DA is preserved.

R{A,B,C,D} F={AB, BC, CD, DA}

Decomposition: R1 = AB, R2 = BC, and R3 = CD

Page 24: Dependency preserving

Exercise #2

R{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?

Page 25: Dependency preserving

Answer to Exercise #2

Let’s start with ABD:Z = AZ R1 = A ABC = A

{A}+ = ABDE{A}+ R1 = ABDE ABC = AB

Update Z = A AB = AB

R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Page 26: Dependency preserving

Answer to Exercise #2

Z = ABZ R2 = A AD = A

{A}+ = ABDE{A}+ R1 = ABDE AD = AD

Update Z = AB AD = ABDThus A BD preserved

R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Page 27: Dependency preserving

Answer to Exercise #2

Based on R3, BE is preserved.Check B E:Z = BZ R1 = B ABC = B

{B}+ = BE{B}+ R1 = BE ABC = B

Update Z = B still the same

R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Page 28: Dependency preserving

Answer to Exercise #2

Z = BZ R2 = B AD = empty setZ R3 = B BDE = B

{B}+ = BE{B}+ R3 = BE BDE = BE

Update Z = B BE = BEThus BE preserved

R{A,B,C,D,E) F={ABD, BE}Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Page 29: Dependency preserving

End

Reference:Yu Hung Chen, “Decomposition”,

http://www.cs.sjsu.edu/faculty/lee/cs157/Decomposition_YuHungChen.ppt, SJSU (lol), 2005

Gary D. Boetticher, “Preserving Dependencies”, http://www.youtube.com/watch?v=olgwucI3thI, University of Houston Clear Lake, 2009

Dr. C. C. Chan, “Example of Dependency Preserving Decomposition”, http://www.cs.uakron.edu/~chan/cs475/Fall2000/ExampleDp%20decomposition.htm, University of Akron, Fall 2000

Tang Nan, “Functional Dependency”, http://www.se.cuhk.edu.hk/~seg3550/2006/tutorial/t9.ppt