❖ 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:
❖ Closures (cont) |
For the question "is X → Y derivable from F?" ...
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 }
❖ 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.
❖ 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
}
❖ Closures (cont) |
For the question "is X → Y derivable from F?" ...
❖ Determining Keys |
Example: determine primary keys for each of the following:
❖ 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?
❖ Minimal Covers (cont) |
Minimal cover Fc for a set F of fd s:
An attribute a is redundant if (F-{d}∪{d'})+ = F+
(where d' is the same as d but with attribute A removed)
❖ 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
❖ 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
❖ Minimal Covers (cont) |
Example: compute minimal cover
E.g. R = ABC, F = { A → BC, B → C, A → B, AB → C }
Working ...
Produced: 4 Nov 2020