550 Lecture13
550 Lecture13
Functional Dependencies
The Evils of Redundancy
• Redundancy is at the root of several
problems associated with relational
schemas:
– Redundant storage, insert/delete/update
anomalies
• Functional dependencies can be used to
identify schemas with such problems and
to suggest refinements
Functional Dependencies
• Most important kind of constraint in the
relational model
• Knowledge about functional dependencies
is vital for redesign of database schemas
to eliminate anomalies & redundancies
Functional Dependencies (FDs)
• A functional dependency X ® Y holds over
relation R, if for every allowable instance r
of R:
– t1Îr, t2 Îr, t1[X]= t2[X] implies t1[Y] = t2[Y]
– i.e., given two tuples in r, if the X values agree,
then the Y values must also agree (X and Y
are sets of attributes)
Formal Definition
• Formally: A ® B
– “A functionally determines B”
– “B is functionally dependent on A”
– A is called the left-hand side (LHS) of the FD
– B is called the right-hand side (RHS) of the FD
• If two tuples of r(R) agree on a set of attributes A
of R, then they must also agree on another set of
attribute B
– i.e., the tuples have the same values in their respective
components for each of these attributes
Pictorially Speaking...
• Assume A ® B
R A’s B’s
u
If t and u then they must
agree on A’s agree on B’s
• R=(A, B, C, D, E, G)
• F: {AB ® C, BC ® AD, D ® E, CE ® B}
• How to compute the closure of {A, B} under F,
i.e., {A, B}+?
– Start with X={A, B}
– Add C to X due to AB ® C; X={A, B, C}
– Add A,D to X due to BC ® AD; X={A, B, C, D}
– Add E to X due to D ® E; X={A, B, C, D, E}
– No more attributes can be added to X
– {A, B}+ = {A, B, C, D, E}
Attribute Closure Usage
• If we can compute closure of any set of attributes,
we can test whether any given functional
dependency {A1, A2,…, An} ® B follows from a
set of dependencies F
– Compute closure of {A1, A2, …, An}+ using F
– If B is in {A1, A2, …, An}+, then {A1, A2, …, An} ® B does
follow from F
• We can also test if K={A1, A2,…, An} is a
candidate key for relation R
– If {A1, A2,…, An}+ is the set of all attributes in R and if K
is minimal
Specifying FDs for a Relation
• Let F be set of FDs specified on R
• Must be able to reason about FDs in F
– Designer usually explicitly states only FDs which are
obvious
– Without knowing exactly what all tuples are, must be
able to deduce other/all FDs that hold on R
– Essential when we discuss design of “good” relational
schemas
• How can we tell if one FD follows from others?
– Use Armstrong’s axioms and reason it out
– OR use attribute closure algorithm