Sub topic 22
Join Dependencies and 5NF
This chapter assumes you know functional dependencies, candidate keys, BCNF, lossless-join decomposition, and multivalued dependencies (MVDs) with 4NF. It finishes the normal-form ladder with fifth normal form. For GATE CS, 5NF carries the least weight of any normal form, so aim to recognize the definition and the standard example.
Join dependencies
A join dependency (JD) on a relation R is written *(R1, R2, ..., Rn), where the attribute sets R1 to Rn together cover all attributes of R. R satisfies the JD if every legal instance of R equals the natural join of its projections onto R1, ..., Rn:
R = πR1(R) ⋈ πR2(R) ⋈ ... ⋈ π_Rn(R)
In other words, the JD says that decomposing R into those pieces is lossless.
- A JD is trivial if one of the Ri is all of R. Every relation satisfies a trivial JD.
- An MVD X ↠ Y is the special case of a binary JD: *(XY, XZ), where Z is the remaining attributes.
- A JD can hold even when no FD and no MVD holds. That case is what 5NF handles.
Fifth normal form
A relation R is in fifth normal form (5NF), also called project-join normal form (PJNF), if for every nontrivial JD *(R1, ..., Rn) that holds on R, every Ri is a superkey of R. Equivalently, every JD that holds must be implied by the candidate keys.
Two consequences follow:
- A relation in 5NF is also in 4NF, BCNF, 3NF, 2NF, and 1NF.
- If a relation has no nontrivial JD apart from those implied by its keys, it cannot be split further without losing information.
A classic example
Consider R(Agent, Company, Product). The business rule is cyclic:
- If agent A represents company C,
- and A sells product P,
- and C makes P,
- then A sells P for C.
The only candidate key is {Agent, Company, Product}, so R has no nontrivial FD. It has no nontrivial MVD either, because no single attribute determines a set of values independently of the other two. R is therefore in BCNF and 4NF. Yet it still has redundancy, because the rule forces some tuples to exist whenever three other tuples exist.
The JD that holds is *(AC, AP, CP), where AC is (Agent, Company), AP is (Agent, Product), and CP is (Company, Product). Decomposing into these three binary tables removes the redundancy. None of the three is a superkey of R, so R violates 5NF until it is split.
Testing a join dependency in code
The script below projects a relation onto the three attribute pairs, joins the projections back, and compares the result with the original.
schema = ("agent", "company", "product")
def project(rel, attrs):
idx = [schema.index(a) for a in attrs]
return {tuple(t[i] for i in idx) for t in rel}
def join3(ac, ap, cp):
return {
(a, c, p)
for (a, c) in ac
for (a2, p) in ap if a2 == a
for (c2, p2) in cp if c2 == c and p2 == p
}
def satisfies_jd(rel):
joined = join3(
project(rel, ("agent", "company")),
project(rel, ("agent", "product")),
project(rel, ("company", "product")),
)
return joined == rel, joined - rel
good = {("A1", "C1", "P1"), ("A1", "C1", "P2"),
("A1", "C2", "P1"), ("A2", "C2", "P1")}
bad = {("A1", "C1", "P2"), ("A1", "C2", "P1"), ("A2", "C1", "P1")}
print(satisfies_jd(good)) # (True, set())
print(satisfies_jd(bad)) # (False, {('A1', 'C1', 'P1')})The good instance obeys the business rule, so the join reproduces it exactly. The bad instance has A1 representing C1, A1 selling P1, and C1 making P1, but no tuple (A1, C1, P1). The join creates that tuple as a spurious tuple, so the JD fails on this instance.
Comparing the higher normal forms
| Normal form | Dependency it targets | Condition |
|---|---|---|
| BCNF | Functional dependency X → Y | X is a superkey |
| 4NF | Multivalued dependency X ↠ Y | X is a superkey |
| 5NF | Join dependency *(R1, ..., Rn) | Each Ri is a superkey, so keys imply the JD |
Gotchas
- You cannot find JDs by looking at the schema. An FD or MVD can be inferred from rules or axioms. A JD is a statement about the real-world meaning of the data, and a single instance can only refute it, never prove it.
- There is no complete set of inference rules for JDs that is as simple as Armstrong's axioms. This is one reason 5NF is rarely tested numerically.
- Decomposing too far costs joins. A three-way join to reconstruct R can be slower than storing R directly, so practical designs usually stop at BCNF or 4NF unless the JD is a real business rule.
- The decomposition must be lossless. A decomposition that is not a valid JD for the data produces spurious tuples, as the
badrelation shows.
Summary of the ladder
Normalization moves from FDs to MVDs to JDs. At each step, the new normal form removes a kind of redundancy the previous one cannot see, and each step needs a more general kind of dependency. In exam practice, the most-tested forms are 2NF, 3NF, and BCNF, with 4NF and 5NF asked mostly as definitions.
Exercise
R(A, B, C) has candidate key ABC and no FDs. It satisfies the JD *(AB, BC, AC) but no nontrivial MVD. Is R in 4NF? Is it in 5NF? Explain.
Show answer
R is in 4NF. With no nontrivial MVD, there is no MVD whose left side must be a superkey, so no violation exists. R is not in 5NF. The JD *(AB, BC, AC) is nontrivial, and none of AB, BC, or AC is a superkey, because the only candidate key is ABC. The JD is not implied by the key, so R violates 5NF. Decomposing R into R1(A, B), R2(B, C), R3(A, C) fixes this.
Exercise
Show that the MVD X ↠ Y on R(X, Y, Z) is the same as the JD *(XY, XZ).
Show answer
The MVD X ↠ Y states that for any two tuples with the same X value, swapping their Y values gives two more tuples that are also in R. The join of πXY(R) and πXZ(R) on X produces exactly all combinations of a Y value and a Z value that share an X value. R equals that join exactly when those swapped tuples are present. So the MVD holds if and only if R satisfies *(XY, XZ).