Introduction

A functional dependency (FD) X→YX \to Y says that the values of attributes XX determine the values of attributes YY: two tuples that agree on XX must agree on YY. FDs are how the real-world rules of an application ("a roll number determines the student's name", "a course and a semester determine the instructor") are written down for a relation.

FDs drive the rest of database design. Keys are defined through them, the later FD-based tests for 2NF, 3NF and BCNF are conditions on them, and lossless decomposition is tested with them. The three computations that the later notes rely on are taught here: attribute closure, implication of an FD, and the canonical (minimal) cover.

Prerequisites

Core concepts

Definition. For attribute sets X,Y⊆RX, Y \subseteq R, relation instance rr satisfies X→YX \to Y if for all tuples t1,t2∈rt_1, t_2 \in r, t1[X]=t2[X]t_1[X] = t_2[X] implies t1[Y]=t2[Y]t_1[Y] = t_2[Y]. The FD holds on schema RR if every legal instance satisfies it. As with keys, an instance can refute an FD but never prove it.

TermMeaning
Trivial FDX→YX \to Y with Y⊆XY \subseteq X; satisfied by every instance
F+F^+ (closure of FF)all FDs logically implied by the set FF
X+X^+ (attribute closure)all attributes AA with X→AX \to A in F+F^+
SuperkeyXX with X+=RX^+ = R
Equivalent setsFF and GG with F+=G+F^+ = G^+
Extraneous attributean attribute that can be removed from a left or right side without changing F+F^+

Armstrong's axioms

For attribute sets X,Y,Z,WX, Y, Z, W:

  1. Reflexivity. If Y⊆XY \subseteq X then X→YX \to Y.
  2. Augmentation. If X→YX \to Y then XZ→YZXZ \to YZ.
  3. Transitivity. If X→YX \to Y and Y→ZY \to Z then X→ZX \to Z.

They are sound (they derive only FDs that hold) and complete (they derive every FD in F+F^+). Derived rules:

  • Union. X→YX \to Y and X→ZX \to Z give X→YZX \to YZ.
  • Decomposition. X→YZX \to YZ gives X→YX \to Y and X→ZX \to Z.
  • Pseudotransitivity. X→YX \to Y and WY→ZWY \to Z give WX→ZWX \to Z.

Not a rule. XY→ZXY \to Z does not give X→ZX \to Z, and X→ZX \to Z with Y→ZY \to Z does not give anything about XX and YY together beyond XY→ZXY \to Z.

How it works: attribute closure

To compute X+X^+, start from XX and repeatedly apply any FD whose left side is already inside the current set, adding its right side, until a full pass adds nothing.

Trace of computing the closure of AB under BE to G, D to E, AB to C, C to D, G to A: pass 1 adds C then D, pass 2 adds E, pass 3 adds G, pass 4 adds nothing, giving ABCDEG
Figure 1. Closure of ABAB under F={BE→G,D→E,AB→C,C→D,G→A}F = \{BE \to G, D \to E, AB \to C, C \to D, G \to A\}, scanning the FDs in the listed order: four passes, result ABCDEGABCDEG, so ABAB is a superkey.

Algorithms and pseudocode

Text
CLOSURE(X, F)
  result <- X
  repeat
      changed <- false
      for each FD (L -> R) in F
          if L is a subset of result and R is not a subset of result then
              result <- result union R; changed <- true
  until not changed
  return result

Each pass costs O(∣F∣⋅∣R∣)O(|F| \cdot |R|) set operations, and there are at most ∣R∣|R| productive passes, so the simple algorithm is O(∣F∣⋅∣R∣2)O(|F| \cdot |R|^2); a counter-based version runs in time linear in the total size of FF.

Uses: X→YX \to Y is in F+F^+ iff Y⊆X+Y \subseteq X^+; XX is a superkey iff X+=RX^+ = R; FF and GG are equivalent iff every FD of GG follows from FF and every FD of FF follows from GG.

Text
CANONICAL-COVER(F)
  replace each FD X -> A1...Ak by X -> A1, ..., X -> Ak      // single attribute right sides
  for each FD X -> A and each attribute B in X               // left-reduce
      if A is in CLOSURE(X - {B}, F) then replace X by X - {B}
  for each FD f in F                                          // remove redundant FDs
      if f follows from F - {f} then delete f
  return F    (optionally merge FDs with equal left sides by union)

The left-reduction test uses the original FF: BB is extraneous in X→AX \to A when A∈(X−{B})+A \in (X - \{B\})^+ computed under FF. Left-reduce before removing redundant FDs; doing it the other way round can leave a redundant FD behind.

Mathematical explanation

Why closure is correct. Every attribute added is justified by transitivity and union from FDs already derived, so the algorithm is sound. For completeness, build a two-tuple instance that agrees exactly on X+X^+ and differs elsewhere: it satisfies every FD of FF (any FD whose left side is inside X+X^+ has its right side inside X+X^+, by the stopping condition), yet violates X→AX \to A for every A∉X+A \notin X^+. So no attribute outside X+X^+ is implied.

Counting trivial FDs. On nn attributes, choosing Y⊆X⊆RY \subseteq X \subseteq R means deciding for each attribute whether it is in YY, in XX only, or in neither: 3n3^n trivial FDs (empty sets allowed). The total number of FDs X→YX \to Y is 2n⋅2n=4n2^n \cdot 2^n = 4^n.

A canonical cover is not unique. F={A→B,B→C,C→A,A→C,C→B,B→A}F = \{A \to B, B \to C, C \to A, A \to C, C \to B, B \to A\} has the two canonical covers {A→B,B→C,C→A}\{A \to B, B \to C, C \to A\} and {A→C,C→B,B→A}\{A \to C, C \to B, B \to A\}; both are minimal and both are equivalent to FF.

Worked examples

Example 1: closure and keys. With FF of Figure 1 on R(A,B,C,D,E,G)R(A, B, C, D, E, G):

  • (AB)+=ABCDEG(AB)^+ = ABCDEG, so ABAB is a superkey; neither A+=AA^+ = A nor B+=BB^+ = B is RR, so ABAB is a candidate key.
  • D+=DED^+ = DE, so D→AD \to A does not hold.
  • BB appears on no right side, so BB is in every key. Trying BB with each other attribute: ABAB, BCBC, BDBD, BEBE, BGBG all have closure RR. The candidate keys are exactly these five.

Example 2: canonical cover. F={A→BC,B→C,AB→D,AD→C}F = \{A \to BC, B \to C, AB \to D, AD \to C\}.

  1. Split: A→B,A→C,B→C,AB→D,AD→CA \to B, A \to C, B \to C, AB \to D, AD \to C.
  2. Left-reduce AB→DAB \to D: A+=ABCDA^+ = ABCD contains DD, so BB is extraneous: A→DA \to D. Left-reduce AD→CAD \to C: A+A^+ contains CC, so DD is extraneous: A→CA \to C, a duplicate.
  3. Remove redundant FDs: A→CA \to C follows from A→BA \to B and B→CB \to C.

Canonical cover: {A→B,B→C,A→D}\{A \to B, B \to C, A \to D\}, or merged, {A→BD,B→C}\{A \to BD, B \to C\}.

Example 3: equivalence. F={A→B,AB→C,C→D}F = \{A \to B, AB \to C, C \to D\} and G={A→BC,C→D,A→D}G = \{A \to BC, C \to D, A \to D\} are equivalent: under FF, A+=ABCDA^+ = ABCD covers A→BCA \to BC and A→DA \to D; under GG, A+=ABCDA^+ = ABCD covers A→BA \to B and AB→CAB \to C. H={A→B,B→C,C→D}H = \{A \to B, B \to C, C \to D\} is not equivalent to FF: B→CB \to C does not follow from FF, because B+=BB^+ = B under FF.

Example 4: does an instance satisfy an FD? Instance of R(A,B,C)R(A, B, C): (1,x,p)(1, x, p), (1,x,q)(1, x, q), (2,y,p)(2, y, p), (3,y,p)(3, y, p). Holds: A→BA \to B (the two tuples with A=1A = 1 both have xx), B→AB \to A? No: yy appears with 2 and 3. C→BC \to B? No: pp appears with xx and yy. AC→BAC \to B: yes. B→CB \to C: no.

Example 5: minimal covers can differ in size. Take the FF of the non-uniqueness remark in the Mathematical explanation: every pair of AA, BB, CC determines each other in both directions, so A+=B+=C+=ABCA^+ = B^+ = C^+ = ABC. A minimal cover here is any set of single-attribute FDs, with no redundant FD, under which all three attributes reach each other. Checking every candidate set gives exactly five:

  • two cycles with 3 FDs: {A→B,B→C,C→A}\{A \to B, B \to C, C \to A\} and {A→C,C→B,B→A}\{A \to C, C \to B, B \to A\};
  • three stars with 4 FDs, one centred on each attribute, for example {A→B,B→A,B→C,C→B}\{A \to B, B \to A, B \to C, C \to B\} centred on BB.

In a star no FD is redundant: dropping B→AB \to A leaves nothing that reaches AA. So "the number of FDs in a minimal cover" is not determined by FF; a question that asks for it has to fix the procedure or the starting order.

Example 6: counting the FDs in F+F^+. R(A,B,C)R(A, B, C), F={A→B,B→C}F = \{A \to B, B \to C\}. For a left side XX, the FDs X→YX \to Y in F+F^+ are exactly those with Y⊆X+Y \subseteq X^+, so there are 2∣X+∣2^{|X^+|} of them (the empty YY included).

XX∅\emptysetAABBCCABABACACBCBCABCABC
X+X^+∅\emptysetABCABCBCBCCCABCABCABCABCBCBCABCABC
2∣X+∣2^{\lvert X^+ \rvert}18428848
  • Total with empty sets allowed: 4343; with a nonempty left side: 4242.
  • Trivial FDs (Y⊆XY \subseteq X): ∑X2∣X∣=33=27\sum_X 2^{|X|} = 3^3 = 27. Nontrivial (Y⊈XY \not\subseteq X): 43−27=1643 - 27 = 16.

State which convention you use: whether the empty set may appear on either side, and whether trivial FDs are counted.

Important properties and observations

  • Right sides split, left sides do not. X→YZX \to YZ is equivalent to the pair X→YX \to Y, X→ZX \to Z; XY→ZXY\to Z does not in general imply X→ZX\to Z or Y→ZY\to Z. A left-side attribute may be removed only when the extraneous-attribute closure test succeeds.
  • Every FD with a superkey on the left holds. Superkeys are exactly the left sides whose closure is RR; candidate keys are inclusion-minimal such sets.
  • Order of canonical-cover steps matters: left-reduce first, then remove redundant FDs.
  • Extraneous on the right: after splitting into single attributes, an extraneous right-side attribute shows up as a redundant FD.
  • FD versus relation property. An FD X→YX \to Y on RR says πXY(r)\pi_{XY}(r) is the graph of a function from XX-values to YY-values (see Relations).

Common misconceptions.

  • "AB→CAB \to C implies A→CA \to C." It does not.
  • "The canonical cover is unique." Several are possible; all are equivalent.
  • "An instance that satisfies X→YX \to Y proves the FD." It only fails to refute it.

GATE examination perspective

  • Closure computations. Compute X+X^+, decide whether an FD is implied, decide whether a set is a key.
  • Candidate keys from FDs. Core attributes (on no right side) plus minimal extensions.
  • Canonical cover. Count the FDs in a minimal cover, or pick which set is a minimal cover of FF.
  • Equivalence of FD sets. Check each direction with closures.
  • Instance questions. Which FDs a given table satisfies.

Summary

Sources

  1. A. Silberschatz, H. F. Korth, S. Sudarshan, Database System Concepts, 7th ed., McGraw-Hill, 2019 (2020 copyright), 7.2 Decomposition Using Functional Dependencies, 7.4 Functional-Dependency Theory.
  2. R. Elmasri, S. B. Navathe, Fundamentals of Database Systems, 7th ed., Pearson, 14.2 Functional Dependencies; 15.1 Further Topics in Functional Dependencies: Inference Rules, Equivalence, and Minimal Cover.

Next steps