Course FD
Course FD
Functional Dependency
Example 1:
PRODUCT(Ref_prod, Label_Prod, PU)
Ref_prod → Label_prod
Ref_prod → PU
Example 2:
EVALUATION(Matricule, Lname, Fname, level, module,
score_module)
R A B C
a1 b1 c1
a1 b1 c2
a2 b2 c2
Armstrong's Axioms
((X Y) Z ) = (X (Y Z))
X Z=Z X
Armstrong's Axioms
1. Reflexivity
Any group of attributes determines itself and
determines each of its attributes (or subgroup of its
attributes).
if X Y Y→X
Example:
brand (n_car,brand) n_car, brand brand
Armstrong's Axioms
2. Augmentation
If an attribute X determines an attribute Y, then any
group composed of X enriched with other attributes
determines a group composed of Y and enriched with
the same other attributes.
Let X, Y and Z be attributes:
X → Y Z, XZ → YZ
Armstrong's Axioms
3. Transitivity
If an attribute X determines an attribute Y and that
attribute Y determines another attribute Z, then X
determines Z.
Example:
n_carmodel AND modelbrand n_carbrand
Armstrong's Axioms
6. Union
x→x x→xx
x→y xx→xy
alors x→xy –--(1)
x→z yx→yz ---(2)
Donc x→yz
Demonstration:
A → B by augmentation with D => AD → BD(1)
D → E by augmentation with B => BD → BE (2)
By transitivity = > AD → BE
Functional Dependency
Trivial Functional Dependencies
A trivial functional dependency is a functional dependency of
the form
X → Y, where Y X.
In other words, a functional dependency is trivial if it is
obtained through the reflexivity property.
Example : Consider
(1) A ,B→ B
(2) B,C→ C
(3) A ,C→ D
(1) is trivial since B A ,B
(2) is trivial since C B ,C
(3) is not trivial since D A ,C
Functional Dependency
Elemantary functional dependencies
Let G be an attribute group and A an attribute, a FD G→A
is elementary if A is not included in G and if there is no
attribute A' of G that determines A.
Example:
AB→C is elementary if neither A nor B
determines C.
Functional Dependency
Say why?
AB→A?
AB→CB?
Functional Dependency
Remark
We can always rewrite a set of FDs into a set of elementary
functional dependencies:
1. Delete trivial DFs obtained by reflexivity,
2. Decompose the non-atomic right part of the FDs into several EFDs.
Functional Dependency
Rewriting FD to EFD
Example:
Consider this set F = {A→B, B→C, B→D, A→E}.
Example
F = {A → B, B → C, B → D, B → E}.
F+ = {A → B, B → C, B → D, B → E, A → C, A → D, A → E}.
Closure of Functional Dependency
Remark
Inference rules have a way to compute the closure of F+.
2. Attribute Closure
We call closure of A, denoted A+, the set of all attributes which are in
functional dependence with A.
X + = {A | X → A F +}
Closure of Functional Dependency
Closing attributes
The following algorithm allows us to calculate this closure:
Algorithm
Begin
A+={A}
while (True) do
for each FD XY of F do
if X is a set in A+ then
A+=A+ ∪ {Y}
end;
end;
if A+ is not changed in this iteration then break;
end;
End
Closure of Functional Dependency
Remark
• If X is a candidate key or a superkey of the
relation R then X+ is the set of attributes of R,
Closure of Functional Dependency
Closing attributes
Exercise
Consider R(A,B,C,D,E,G,H) and FD set F={GA,ABC, BD, CDE, CEGH}
a) Compute G+
G+={G}
1st iteration
GA: G∈G+ then G+={G,A}
ABC:AB ∉ G+ then G+ unchanged
BD: B ∉ G+ then G+ unchanged
CDE: CD ∉ G+ then G+ unchanged
CEGH: CE ∉ G+ then G+ unchanged
G+={G,A} has been changed, continue
Closure of Functional Dependency
Closing attributes
F={GA,ABC, BD, CDE, CEGH}
2nd iteration
G+={G,A}
GA: G∈G+ then G+={G,A} then G+ unchanged
ABC:AB ∉ G+ then G+ unchanged
BD: B ∉ G+ then G+ unchanged
CDE: CD ∉ G+ then G+ unchanged
CEGH: CE ∉ G+ then G+ unchanged
G+={G,A}: G+ unchanged, STOP!
Closure of Functional Dependency
Closing attributes
F={GA,ABC, BD, CDE, CEGH}
2) Compute BC+
BC+={B,C}
1st iteration
GA : G ∉ BC+ then BC+ is unchanged
ABC:AB ∉ BC+ then BC+ is unchanged
BD: B ∈ BC+ then BC+ ={B,C,D}
CDE: CD ∈ BC+ then BC+ ={B,C,D,E}
CEGH: CE ∈ BC+ then BC+ ={B,C,D,E, G,H}
BC+={B,C,D,E, G,H} has been changed, continue
Closure of Functional Dependency
Closing attributes
F={GA,ABC, BD, CDE, CEGH}
BC+={B,C,D,E, G,H}
2nd iteration
GA : G ∈ BC+ ={A,B,C,D,E, G,H}
ABC:AB ∈ BC+ then BC+ is unchanged
BD: B ∈ BC+ then BC+ is unchanged
CDE: CD ∈ BC+ then BC+ is unchanged
CEGH: CE ∈ BC+ then BC+ is unchanged
BC+={A,B,C,D,E, G,H} has been changed, Continue
Closure of Functional Dependency
Closing attributes
F={GA,ABC, BD, CDE, CEGH}
BC+={A,B,C,D,E, G,H}
3rd iteration
GA : G ∈ BC+ then BC+ is unchanged
ABC:AB ∈ BC+ then BC+ is unchanged
BD: B ∈ BC+ then BC+ is unchanged
CDE: CD ∈ BC+ then BC+ is unchanged
CEGH: CE ∈ BC+ then BC+ is unchanged
BC+=={A,B,C,D,E, G,H} is unchanged, STOP!
So, BC+={A,B,C,D,E, G,H}
Closure of Functional Dependency
Exercise
Let R(A,B,C,D,E,F) and G={B→E, A→BC, CD→EF}
Compute B+, AD+
B+={B,E}
AD+={A,D,B,C,E,F}
Closure of Functional Dependency
Coverage and Minimum Coverage
Definition of a cover
Let R be a relation and F1, F2 two sets of FDs defined in R:
F1 is a cover of F2 iff F2+ is included in F1+
Remark
To show that F1 is a cover of F2, it suffices to show that any FD of F2
belongs to F1+ (is derivable from the FDs of F1)
Closure of Functional Dependency
Example
R(A,B,C,D,E,F)
F={(1) ABC, (2) BD}
F’={(3) ABD, (4) ABC, (5) BD}
Show that F’ is a cover of F.
(1) ABC
(3) By decomposition (6) AB and (7) AD
(6) and (4) yield by pseudo-transitivity (8) AC
(6) and (8) yield by union ABC so (1) is derivable by F’ (belongs
to F’+)
(2) is identical to (5) so df(2) is derivable by F’ (belongs to F’+)
Hence, F’ is a cover of F
Definition of two sets of equivalent DFs
Example :
F = {A→B, A→C, B→C, C→B} admits two minimal cover:
Example
Let F={ACD, BAF, CBE, FEC}
Property 1:
K is a key of R iff:
a) K→A1,A2,...,An
"All-key" relation
A B C D E
a1 b2 c2 d3 e2
a1 b2 c2 d1 e4
a2 b3 c2 d1 e5
a2 b4 c5 d1 e5
Key
Superkey
Exercise
Consider R(A,B,C,D,E,F) and FD set{ACD, BAF, CBE,
FEC}
Determine candidate keys?
Candidate keys
Let the superkey formed from the set of attributes of R be: ABCDEF
or let the superkey formed from the attributes of the left members of
the FDs (determinants): ABCF