Sub topic 11
Functional Dependencies and Armstrong's Axioms
This chapter assumes you know what a relation, tuple, and key are, and that you can read basic set notation (subset, union). It builds the tool that every later normalization step depends on: the functional dependency, and the rules for reasoning about it.
What a Functional Dependency Says
A functional dependency (FD) is a constraint between two sets of attributes of one relation. We write X -> Y, read "X determines Y". It holds in a relation R when any two tuples that agree on all attributes of X also agree on all attributes of Y.
Formally, for every pair of tuples t1 and t2 in r(R): if t1[X] = t2[X], then t1[Y] = t2[Y].
Two points are easy to get wrong:
- An FD is a statement about all legal instances of the schema, not about the rows you happen to see. A single table instance can only show that an FD is violated. It can never prove that the FD holds.
- X -> Y says nothing when two tuples differ on X. Different X values may map to the same Y value.
Consider this instance of R(A, B, C):
| A | B | C |
|---|---|---|
| 1 | x | p |
| 2 | x | q |
| 3 | y | p |
| 1 | x | r |
- A -> B holds. Both tuples with A = 1 have B = x.
- B -> A does not hold. B = x appears with A = 1 and A = 2.
- A -> C does not hold. A = 1 appears with C = p and C = r.
- AC -> B holds. No two tuples share the same (A, C) pair with different B values.
A relation can satisfy FDs that the designer never intended. The FDs you use for design must come from the meaning of the data, for example "an employee ID identifies exactly one name".
Trivial and Non-Trivial FDs
X -> Y is trivial if Y is a subset of X. For example, AB -> A always holds. It is non-trivial if Y is not a subset of X, and completely non-trivial if X and Y share no attributes. GATE questions often say "non-trivial" when they mean the stricter sense, so read the wording.
Keys are a special case of FDs. A set K is a superkey of R exactly when K -> R (all attributes of R) holds.
Armstrong's Axioms
Given a set F of FDs, other FDs follow logically from it. Armstrong's axioms are three inference rules that generate all of them. Let X, Y, Z be attribute sets.
- Reflexivity. If Y is a subset of X, then X -> Y.
- Augmentation. If X -> Y, then XZ -> YZ for any Z.
- Transitivity. If X -> Y and Y -> Z, then X -> Z.
The axioms are sound: they only derive FDs that truly follow from F. They are also complete: every FD that follows from F can be derived with them. Together these properties mean that "derivable by the axioms" and "logically implied" are the same thing.
Derived Rules
Three more rules follow from the axioms and save time in proofs.
| Rule | Statement | Derivation sketch |
|---|---|---|
| Union | X -> Y and X -> Z give X -> YZ | Augment X -> Y by X to get X -> XY. Augment X -> Z by Y to get XY -> YZ. Apply transitivity. |
| Decomposition (splitting) | X -> YZ gives X -> Y and X -> Z | YZ -> Y by reflexivity. Apply transitivity. |
| Pseudotransitivity | X -> Y and WY -> Z give WX -> Z | Augment X -> Y by W to get WX -> WY. Apply transitivity with WY -> Z. |
Splitting works only on the right side. If XY -> Z holds, you cannot conclude X -> Z or Y -> Z. This is a frequent exam trap.
A Worked Derivation
Let R(A, B, C, D, E) with F = { A -> B, B -> C, CD -> E }. Show that AD -> E.
- A -> B (given)
- B -> C (given)
- A -> C (transitivity on 1 and 2)
- AD -> CD (augmentation of 3 by D)
- CD -> E (given)
- AD -> E (transitivity on 4 and 5)
Each line cites a given FD or one rule applied to earlier lines. This is the format a proof question expects.
The Closure of a Set of FDs
The closure F+ is the set of all FDs implied by F. It can be very large. A relation with n attributes has 2^n subsets, so there are up to 4^n candidate FDs, and most are trivial. Computing F+ directly is rarely practical. The next chapter shows how to test a single FD without building F+, by computing the closure of an attribute set.
Two sets of FDs F and G are equivalent when F+ = G+. This idea returns when we compute a minimal cover.
Checking Whether an FD Holds in a Table
You can test an FD against stored data by grouping on the left side and checking that each group has exactly one right-side value. This is useful for finding which FDs a data set violates.
def fd_holds(rows, lhs, rhs):
"""rows: list of dicts; lhs, rhs: lists of column names."""
seen = {}
for row in rows:
key = tuple(row[c] for c in lhs)
val = tuple(row[c] for c in rhs)
if key in seen and seen[key] != val:
return False
seen[key] = val
return True
rows = [
{"A": 1, "B": "x", "C": "p"},
{"A": 2, "B": "x", "C": "q"},
{"A": 3, "B": "y", "C": "p"},
{"A": 1, "B": "x", "C": "r"},
]
print(fd_holds(rows, ["A"], ["B"])) # True
print(fd_holds(rows, ["B"], ["A"])) # False
print(fd_holds(rows, ["A"], ["C"])) # False
print(fd_holds(rows, ["A", "C"], ["B"])) # TrueA True result only means the FD is consistent with this data. It does not establish the FD as a design rule.
Common Errors
- Reading an FD from a sample table as a rule. Data can refute an FD but never confirm it.
- Splitting the left side. AB -> C does not give A -> C.
- Reversing an FD. A -> B does not give B -> A.
- Forgetting augmentation adds the same set to both sides. From A -> B you get AC -> BC, not AC -> B alone as a new fact. (AC -> B is true, but it follows by augmentation then splitting the right side.)
- Confusing trivial with non-trivial. An FD such as AB -> B is always true and carries no design information.
- Assuming a key is needed to state an FD. FDs exist between any attribute sets. Keys are only the FDs whose right side is the whole relation.
Exercise
Let R(A, B, C, D) with F = { A -> B, BC -> D }. Using Armstrong's axioms, derive AC -> D. Then say whether A -> D follows from F.
Show answer
Derivation: (1) A -> B, given. (2) AC -> BC, augmentation of 1 by C. (3) BC -> D, given. (4) AC -> D, transitivity on 2 and 3. A -> D does not follow. Starting from A alone, only A -> B is usable, because BC -> D needs C on the left. The attribute closure of A is {A, B}, which does not contain D.
Exercise
A table has these rows (P, Q, R): (1, a, x), (1, a, y), (2, b, x), (3, b, x). Which of P -> Q, Q -> P, and R -> Q hold in this instance? Can you conclude that any of them is a design FD?
Show answer
P -> Q holds, because each P value has one Q value (1 -> a, 2 -> b, 3 -> b). Q -> P fails, because Q = a pairs with P = 1 only but Q = b pairs with P = 2 and P = 3. R -> Q fails, because R = x pairs with Q = a and Q = b. No, you cannot conclude that P -> Q is a design FD from this data alone. It only means the data does not contradict it. The meaning of the attributes must justify it.