Closing sets of FDs Basis: set F of FDs that hold in R; F1 ≈ F Minimal basis B for R: 1. B - basis 2. f B has singleton r.s. 3. If any FD is removed from B, the result is not a basis 4. If f B we remove at least one attr. from the l.s. of f, the result is not a basis Min_basis(F) { B = F; while ( ( f = X Y ) B; | Y| >1) split( f ); while ( f B | f B – f) B=B-f; while( ( f = X Y ) B | | X| >1, Z=X-xi , Z Y B) X Y := Z Y } Projecting FDs R(S), F, S1 S, R1 = πS1 R F1 - projection of F: F1 follows from F and involves only attr. from S1 Proj_FD(S,F,S1) { F1=Ǿ // Init for (all X S1) {compute X+F ; for(all f= XY nontrivial, Y X+F , Y S1) F1:=F1+f } F1:=min_basis(F1);} RDB Design Problem: redundancy; update, insertion, deletion anomalies Solution: decomposition R(S), R1(S1), R2(S2), … , Rn(Sn) S1, S2, … , Sn S; S1 S2 … Sn = S; R1 = π S1 R , R2 = π S2 R , Rn = π Sn R Reason: dependencies Normal forms: 1NF , … , 4NF FD types: X Y FFD (Full) ∄ 𝑋′ X PFD (Partial) ∃ 𝑋′ X TFD (Transitive) ∃ 𝑍 S X’Y X’Y XZ, ZY 2NF: no PFD on the key R(S), key K, PFD KY, K’ K, FFD K’Y Dec2NF: S1 = (K’, Y), S2 = (K, S-K-Y) Decomposition examples Recovering of info from decomposition: natural join Theorem. R(S), S = X Y Z, F = {Y Z} R = π X Y R |X| π Y Z R Example R(X,Y,Z), Y Z R(X,Y,Z), Y -/-> Z, Y -/-> X Lossless-join dec. Lossy-join dec. X Y Z x1 y z x2 y z X Y x1 y x2 y X Y Z x1 y z1 x2 y z2 Y Z y z X Y Z x1 y z x2 y z Join - the only way to recover! X Y x1 y x2 y Y Z y z1 y z2 X Y Z x1 y z1 x1 y z2 x2 y z1 x2 y z2