Functional Dependencies


Functional Dependencies

Simon
Welcome to Module 23 of Database Management Systems. We’re building on functional dependencies and using them to reason about relational database design. The big picture is that functional dependencies help us identify keys, test whether dependencies follow from what we already know, and guide decompositions into better-designed relations.

Hope
Let’s begin with the basic definition. If we write α determines β, then in every valid instance of the relation, any two tuples that agree on the attributes in α must also agree on the attributes in β. In other words, matching on α guarantees matching on β.

Simon
And the three foundational rules for deriving dependencies are Armstrong’s axioms: reflexivity, augmentation, and transitivity. They’re sound, meaning they only produce dependencies that really follow, and complete, meaning every dependency implied by the given set can be derived using them.

Hope
A simple example shows transitivity: if A determines B and B determines C, then A determines C. If we repeatedly apply Armstrong’s axioms to a set F of dependencies and collect everything we can derive, we get the closure of F, written F plus.

Simon
Here’s a larger illustration. Suppose the attributes include A, B, C, G, H, and I, and the dependencies include A determines B, B determines H, A determines C, CG determines H, and CG determines I. From the first two, transitivity gives A determines H.

Hope
We can also combine rules to derive dependencies involving more attributes. From A determines C, augmentation by G gives AG determines CG. Since CG determines I, transitivity now gives AG determines I. Likewise, CG determines H and CG determines I can be combined to give CG determines HI.

Simon
That kind of reasoning can be automated. Start with F plus initialized to F. Apply reflexivity and augmentation to dependencies already in the set, and check pairs of dependencies for transitivity: if the right side of one matches the left side of another, add the resulting dependency.

Hope
Then repeat. There are only finitely many attributes, so there are only finitely many possible functional dependencies over them. Eventually no new dependencies are added, and that stopping point is F plus. This is a direct, though not necessarily the most efficient, way to compute the closure.

Simon
As we work with the axioms, we can also use some useful derived rules. They’re not new foundations; they follow from the original three. The union rule says that if α determines β and α determines γ, then α determines βγ.

Hope
That makes intuitive sense: if two tuples agree on α, they must agree on β, and they must also agree on γ, so they agree on both together. The decomposition rule goes in the other direction: if α determines βγ, then α determines β and α determines γ.

Simon
And pseudo-transitivity says that if α determines β and γβ determines δ, then γα determines δ. These derived rules are sound and handy, but they aren’t required for completeness because they can be proved from reflexivity, augmentation, and transitivity.

Hope
Now let’s shift from the closure of dependencies to the closure of attributes. Given a set of attributes α and functional dependencies F, α plus is the set of every attribute that α can determine using F. It always includes α itself.

Simon
To compute it, initialize the result to α. Then look through the dependencies in F: whenever a dependency’s left side is already contained in the result, add its right-side attributes. Keep repeating until the result stops growing.

Hope
For the example we just used, start with AG. Since A is present, A determines B and A determines C, so add B and C. Now CG is present, so CG determines H and I; add those too. The closure is AG plus equals A, B, C, G, H, and I.

Simon
That closure immediately helps us test whether AG is a superkey. A superkey determines every attribute in the relation, and AG plus contains all six attributes, so AG is a superkey.

Hope
To decide whether it’s a candidate key, we also need minimality: no proper subset should still be a superkey. A plus contains A, B, C, and H, but not all the attributes. G appears on no right-hand side in the given dependencies, so G alone cannot determine the other attributes. Neither A nor G is a superkey, which makes AG a minimal superkey: a candidate key.

Simon
Attribute closure answers another useful question: does a proposed dependency α determines β follow from F? Compute α plus. If β is a subset of α plus, then the dependency holds; if not, it doesn’t follow from the given dependencies.

Hope
And attribute closure can also be used to construct F plus. Consider each possible set of attributes γ, compute γ plus, and include dependencies from γ to each attribute set contained in that closure. This gives another route to the dependency closure, often more efficient than repeatedly manipulating individual dependencies.

Simon
With those tools in place, we can turn to normalization. Boyce-Codd Normal Form, or BCNF, applies to a relation that is already in first normal form. A relation is in BCNF if every dependency that holds is either trivial—its right side is already contained in its left side—or has a left side that is a superkey.

Hope
So a nontrivial dependency from something that isn’t a superkey signals a BCNF violation. For example, in an instructor-and-department relation, department name may determine building and budget. If department name isn’t a superkey of that whole relation, that dependency violates BCNF.

Simon
To address a violating dependency α determines β, split the relation into two schemas: one containing α together with β, and another containing the original attributes except for the right-side attributes that aren’t already in α. That is, the second schema is R minus β minus α.

Hope
In our department example, the first relation is department name, building, and budget. The second is the instructor information: ID, name, salary, and department name. The department dependency is handled in the first relation, while ID determines the instructor details in the second. With those dependencies, each relation has a superkey on the left of its nontrivial dependencies, so both are in BCNF.

Simon
But decomposition raises an important question: can we reconstruct the original information? A decomposition is lossless if, for every valid instance, taking the natural join of the decomposed relations gives exactly the original relation—not extra combinations.

Hope
For a two-relation decomposition, the schemas must cover all the original attributes and share attributes to join on. The key condition is that their common attributes must form a key for at least one of the two relations. Then the shared values identify unique matching records on that side, avoiding spurious combinations.

Simon
In the instructor-and-department decomposition, the common attribute is department name. It is a key of the department relation because it determines building and budget. So joining the instructor relation with the department relation pairs each instructor with the unique matching department information, giving a lossless decomposition.

Hope
There’s a second question: are the dependencies preserved? Dependency preservation means we can check the original dependencies by checking the decomposed relations individually, without having to join them back together. That matters because joins can be expensive.

Simon
The instructor-and-department example preserves its dependencies: the instructor dependencies can be checked in the instructor relation, and department name determining building and budget can be checked in the department relation. But BCNF does not always preserve dependencies.

Hope
Here’s a counterexample. Take attributes C, S, and Z—city, street, and ZIP or postal code—with dependencies CS determines Z and Z determines C. CS is a key. The dependency Z determines C violates BCNF because it’s nontrivial and Z isn’t a superkey.

Simon
Decomposing on Z determines C gives relations ZC and SZ. Their shared attribute is Z, and Z determines C, so Z determines the whole ZC relation. That makes the decomposition lossless under the shared-key condition.

Hope
But CS determines Z involves all three attributes, so it can’t be checked in either ZC or SZ alone. You would need to join them back together to check it. So this BCNF decomposition is lossless, but it does not preserve all the dependencies.

Simon
Third Normal Form, or 3NF, relaxes BCNF to help preserve dependencies. For every dependency α determines β in F plus, 3NF allows it if the dependency is trivial, if α is a superkey, or if each attribute on the nontrivial right side—each attribute in β minus α—is part of at least one candidate key.

Hope
That last condition is the relaxation. The attributes on the right don’t have to belong to the same candidate key; each just has to be a member of some candidate key. Every BCNF relation is in 3NF, but not every 3NF relation is in BCNF. The relaxation is designed to support dependency preservation.

Simon
So the goals of normalization are not simply ‘decompose as much as possible.’ We want well-structured relations, a lossless decomposition so we can recover the original information, and preferably dependency preservation so constraints can be checked without costly joins.

Hope
There are trade-offs. Decomposition can make some queries more expensive because they require joins—for example, finding an instructor’s building may require joining the instructor and department relations. But keeping data together can create redundancy and anomalies. Good design balances those competing costs.

Simon
And BCNF, while strong, doesn’t solve every kind of redundancy. Imagine an instructor-info relation with ID, child name, and phone, where an instructor can have multiple children and multiple phone numbers, independently.

Hope
If an instructor has two children and two phone numbers, storing every combination can repeat information. Adding a phone number might require multiple tuples, and an update might need to be repeated. Yet there may be no nontrivial functional dependency at all, so the relation can be in BCNF—and in 3NF—while still having this problem.

Simon
Separating the children from the phone numbers can represent those independent facts more cleanly and avoid that combination-based redundancy. Since functional dependencies don’t detect the problem, it motivates higher normal forms, typically Fourth Normal Form, which we’ll study later.

Hope
Today’s main tools are functional-dependency closure and attribute closure. They help us derive what follows from a set of dependencies, find and test keys, and reason about whether a decomposition is lossless and whether it preserves dependencies.

Simon
And the central design lesson is that normal forms address different concerns. BCNF strengthens the structure of dependencies; 3NF relaxes that condition to support preservation; and even these forms may not remove every kind of redundancy. We’ll continue exploring the theory and its practical trade-offs in the next module.

Ask anything
We've read this whole study set, so questions about it get the best answers.