Attribute & FD Closure

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 12

Closure of FD and Attributes

Closure of a set of FDs


Given a set of FDs F on a relation R, it may be possible that several other FDs must also hold for R For Example, R=(A,B,C) & FDs, A B & B C hold in R, then FD A C also holds on R For a given value of A, there can be only one corresponding value of B, & for that value of B, there can be only one corresponding value for C The closure of F is the set of all FDs that can be inferred from F, & is denoted by F+

9/21/2010

Equivalent Set of FDs


Two sets of FDs, S & T, are equivalent if the set of relation instances satisfying S is exactly the same as the set of relation instances satisfying T S follows from T if every relation instance that satisfies T also satisfies all FDs in S S & T are equivalent iff S follows from T, & T follows from S

9/21/2010

Trivial, Non-trivial & Completely Non-trivial FDs A B


Trivial If Bs are a subset of the As Non-trivial If at least one of the Bs is not among As Completely Non-trivial If none of the Bs is also one of the As

9/21/2010

Closure of a set of FDs


It is not sufficient to consider just the given set of FDs We need to consider all FDs that hold Given F, more FDs can be inferred Such FDs are said to be logically implied by F F+ is the set of all FDs logically implied by F We can compute F+ using formal definition of FD If F were large, this process would be lengthy & cumbersome Axioms or Rules of Inference provide simpler technique Armstrong's Axioms

9/21/2010

Inference Rules for FDs


Armstrong's inference rules: IR1. (Reflexive) If Y X, then X Y IR2. (Augmentation) If X Y, then XZ YZ (Notation: XZ stands for X U Z) IR3. (Transitive) If X Y and Y Z, then X Z IR1, IR2, IR3 form a sound & complete set of inference rules

Never generates any wrong FD

Generate all FDs that hold

9/21/2010

Inference Rules for FDs


Some additional inference rules that are useful: IR4: Decomposition: If X YZ, then X Y & X Z IR5: Union: If X Y & X Z, then X YZ IR6: Psuedotransitivity: If X Y & WY Z,then WX Z Above three inference rules, as well as any other inference rules, can be deduced from IR1, IR2, and IR3 (completeness property)

9/21/2010

Example
R = (A, B, C, G, H, I) F={ ApB ApC CG p H CG p I B p H} some members of F+ ApH by transitivity from A p B and B p H AG p I by augmenting A p C with G, to get AG p CG and then transitivity with CG p I CG p HI 9/21/2010 By union rule

Procedure for Computing F+


To compute the closure of a set of functional dependencies F: F+=F repeat for each functional dependency f in F+ apply reflexivity and augmentation rules on f add the resulting functional dependencies to F + for each pair of functional dependencies f1and f2 in F + if f1 and f2 can be combined using transitivity then add the resulting functional dependency to F + until F + does not change any further NOTE: We shall see an alternative procedure for this task later
9/21/2010 9

Closure of Attribute Sets


Set of attributes functionally determined by X Closure of a set of attributes X with respect to F is the set X+ of all attributes that are functionally determined by X Algo. for computing closure: compute F+ & take all FDs with X on the LHS & take union of the RHS of all such FDs X+ can be calculated by repeatedly applying IR1, IR2, IR3 using the FDs in F Both these approaches become cumbersome if F is large & consequently F+ is larger

9/21/2010

10

Closure of Attribute Sets


Given a set of attributes E define the closure of E under F (denoted by E+) as the set of attributes that are functionally determined by E under F Algorithm to compute E+, the closure of E under F result := E; while (changes to result) do for each F p K in F do begin if F result then result := result K end
Try to find out why this algorithm works! Complexity of this algorithm Can you do any better?

9/21/2010

11

Uses of Attribute Closure

There are several uses of the attribute closure algorithm: Testing for superkey: To test if E is a superkey, we compute E+, and check if E+ contains all attributes of R. Testing functional dependencies To check if a functional dependency E p F holds (or, in other words, is in F+), just check if F E+. That is, we compute E+ by using attribute closure, and then check if it contains F. Is a simple and cheap test, and very useful Computing closure of F For each K R, we find the closure K+, and for each S K+, we output a functional dependency K p S. 9/21/2010

12

You might also like