Inference on FDs

COMP3311 20T3 ♢ Inference on FDs ♢ [0/11]
❖ Closures

Given a set F of fds, how many new fds can we derive?

For a finite set of attributes, there must be a finite set of derivable fds.

The largest collection of dependencies that can be derived from F is called the closure of F and is denoted F+.

Closures allow us to answer two interesting questions:

COMP3311 20T3 ♢ Inference on FDs ♢ [1/11]
❖ Closures (cont)

For the question "is X → Y derivable from F?" ...


For the question "are F and G equivalent?" ...
Unfortunately, closures can be very large, e.g.

R = ABC,     F = { AB → C,   C → B }
F+ = { A → A,   AB → A,   AC → A,   AB → B,   BC → B,   ABC → B,  
            C → C,   AC → C,   BC → C,   ABC → C,   AB → AB,   . . . . . . ,
            AB → ABC,   AB → ABC,   C → B,   C → BC,   AC → B,   AC → AB }

COMP3311 20T3 ♢ Inference on FDs ♢ [2/11]
❖ Closures (cont)

Algorithms based on F+ rapidly become infeasible.

To solve this problem ...

Given a set X of attributes and a set F of fds, the closure of X (denoted X+) is

Determining X+ from {X→Y, Y→Z}  ...  X → XY → XYZ = X+

For computation, |X+| is bounded by the number of attributes.

COMP3311 20T3 ♢ Inference on FDs ♢ [3/11]
❖ Closures (cont)


Algorithm for computing attribute closure:

Input: F (set of FDs), X (starting attributes)
Output: X+ (attribute closure)

Closure = X
while (not done) {
   OldClosure = Closure
   for each A → B such that A ⊂ Closure
      add B to Closure
   if (Closure == OldClosure) done = true
}

COMP3311 20T3 ♢ Inference on FDs ♢ [4/11]
❖ Closures (cont)

For the question "is X → Y derivable from F?" ...


For the question "are F and G equivalent?" ...
For the question "what are the keys of R implied by F?" ...
COMP3311 20T3 ♢ Inference on FDs ♢ [5/11]
❖ Determining Keys

Example: determine primary keys for each of the following:

  1. FD  =  { A → B, C → D, E → FG }
    • A?  A+ = AB, so no ...  AB?  AB+ = ABCD, so no
    • ACE?  ACE+ = ABCDEFG, so yes!

  2. FD  =  { A → B, B → C, C → D }
    • B?  B+ = BCD, so no ...  A?  A+ = ABCD, so yes!

  3. FD  =  { A → B, B → C, C → A }
    • A?  A+ = ABC, so yes! ...  B?  B+ = ABC, so yes!
COMP3311 20T3 ♢ Inference on FDs ♢ [6/11]
❖ Minimal Covers

For a given application, we can define many different sets of fds with the same closure (e.g. F and G where F+ = G+)

Which one is best to "model" the application?

If we can ... Better still, can we derive the smallest complete set of fds?
COMP3311 20T3 ♢ Inference on FDs ♢ [7/11]
❖ Minimal Covers (cont)

Minimal cover Fc  for a set F of fd s:

An fd d is redundant if (F-{d})+ = F+

An attribute a is redundant if (F-{d}∪{d'})+ = F+
(where d' is the same as d but with attribute A removed)

COMP3311 20T3 ♢ Inference on FDs ♢ [8/11]
❖ Minimal Covers (cont)

Algorithm for computing minimal cover:

Inputs: set F of fds
Output: minimal cover Fc of F
Fc = F
Step 1: put f ∈ Fc into canonical form
Step 2: eliminate redundant attributes from f ∈ Fc
Step 3: eliminate redundant fds from Fc

Step 1: put fd s into canonical form

for each f ∈ Fc like X → {A1,...,An}
    remove X → {A1,...,An} from Fc
    add X → A1, ... X → An to Fc
end

COMP3311 20T3 ♢ Inference on FDs ♢ [9/11]
❖ Minimal Covers (cont)

Step 2: eliminate redundant attributes

for each f ∈ Fc like X → A
    for each b in X
        f' = (X-{b}) → A;   G = Fc - {f} ∪ {f'}
        if (G+ == Fc+) Fc = G
    end
end

Step 3: eliminate redundant functional dependencies

for each f ∈ Fc
    G = Fc - {f}
    if (G+ == Fc+) Fc = G
end

COMP3311 20T3 ♢ Inference on FDs ♢ [10/11]
❖ Minimal Covers (cont)


Example: compute minimal cover

E.g. R = ABC, F = { A → BC,   B → C,   A → B,   AB → C }

Working ...

This gives the minimal cover   Fc = { A → B,   B → C }.
COMP3311 20T3 ♢ Inference on FDs ♢ [11/11]


Produced: 4 Nov 2020