Relational Database Design - FDs
Relational Database Design - FDs
Employees’ Skill
Employee ID Address Skill
426 24 Vile Parle Typing
426 24 Vile Parle Shorthand
519 21 Juhu Public speaking
519 23 Bandra Carpentry
Anomalies
2. Insertion anomaly: Until the new faculty member, Dr. Hayes, is
assigned to teach at least one course his details cannot be recorded.
Faculty and Their Courses
Faculty ID Name Hire Date Course Code
A B C A B B C
1 A 1 1 A
2 B 2 2 B
r r1 r2
A B C
r1 r2
1 A
2 B
Decomposition does not always work
Not all compositions are lossless-join decomposition
Suppose we decompose
employee(ID, name, street, city, salary) into:
employee1 (ID, name)
employee2 (name, street, city, salary)
The next slide shows how we lose information -- we cannot
reconstruct the original employee relation using employee1 and
employee2 -- and so, this is a lossy decomposition.
A Lossy Decomposition
Example: A Lossy Decomposition
Consider Supplier_Parts schema: Supplier_Parts (S#, Sname,
City, P#, Qty)
Decompose it as:
Supplier(S#, Sname, City, Qty) and Parts(P#, Qty)
A B
1 4
1 5
3 7
name ID
Trivial Functional Dependencies
A functional dependency of the form is trivial if
Example:
ID, name ID
name name
AG I
by augmenting A C with G, to get AG CG
given
augmentation rule
union of identical sets
given
augmentation rule
transitivity rule and set union commutativity
Computing F+ (Contd..)
ii. Decomposition: If holds, then holds and holds
given
reflexivity rule
transitivity rule
reflexivity rule
transitive rule
AG H
By pseudotransitivity A C and CG H, to get AG H
AG I
By pseudotransitivity A C and CG I, to get AG I
CG HI
by Union CG H and CG I
Closure of Attribute Sets
Given a set of attributes , define the closure of under F
(denoted by +) as the set of attributes that are functionally
determined by under F.
Algorithm to compute +, the closure of under F
result := ;
repeat
for each functional dependency in F do
begin
if ⊆ result then result := result ∪ ;
end
until (result does not change)
Note: Since ⊆ result, means , and (given) ,
hence result := result ∪
Example: Closure of Attribute Sets
R = (A, B, C, G, H, I)
F = {A B
AC
CG H
CG I
B H}
(AG)+
1. result = AG
2. result = ABCG (A B and A C)
3. result = ABCGH (CG H and CG ⊆ ABCG)
4. result = ABCGHI (CG I and CG ⊆ ABCGH)
{A B, B C, A D}
Forward: (1) A CD A C and A D (2) A B, B C AC
Reverse: (1) A B, B C A C (2) A C, A D A CD
E.g.: (ii) on LHS: {A B, B C, AC D} can be simplified to
{A B, B C, A D}
Forward: (1) A B, B C AC A AC
(2) A AC, AC D AD
Reverse: (1) A D AC D
Canonical cover: A canonical cover of F, denoted by Fc is a
“minimal” set of functional dependencies equivalent to F, having no
redundant dependencies or redundant parts of dependencies.
Canonical Cover (Contd..)
For Example: RHS
{A B, B C, A CD} {A B, B C, A D}
A CD A C and A D
A B, B C AC
OR
A+ = ABCD
{A B, B C, A D} {A B, B C, A CD}
A B, B C AC
A C, A D A CD
OR
A+ = ABCD
Steps:
1. Make all FDs having singleton right hand side
2. For each FD remove extraneous attributes, if exists (in LHS)
3. Removal of redundant FDs
Lossless-join Decomposition
We have formally defined lossless-join decomposition earlier.
Let R be a relation schema, and let R1 and R2 form a decomposition
of R. For the case of R = (R1, R2), we require that for all possible
relations r on schema R
r = R1 (r) R2 (r)
Dependency Preservation
Let F be a set of functional dependencies on a schema R,
and let R1, R2, . . . , Rn be a decomposition of R.
Let Fi be the set of all functional dependencies in F+ that
include only attributes of Ri
A decomposition is dependency preserving, if
(F1 ∪ F2 ∪ ……..∪ Fn)+ = F+
Test for Dependency Preservation
To check if a dependency is preserved in a decomposition of
R into R1, R2, ….., Rn we apply the following test, with attribute
closure done with respect to F (it avoids computing F+):
result =
repeat
for each Ri in the decomposition
t = (result ∩ Ri)+ ∩ Ri
result = result ∪ t
until (result does not change)
If result contains all attributes in , then the functional dependency
is preserved.
We apply the test on all dependencies in F to check if a
decomposition is dependency preserving.
Example: Test for Dependency Preservation
R (ABCDEF):
F = {A BCD, A EF, BC AD, BC E, BC F, B F, D E}
D = {ABCD, BF, DE} [Decomposition]
On projections:
ABCD (R1) BF (R2) DE (R3)
A BCD BF DE
BC AD