Fd covers
Click here to load reader
-
Upload
anju-renjith -
Category
Technology
-
view
560 -
download
0
Transcript of Fd covers
3/23/2010
1
Covers for Functional
Dependencies
CIS-611. Victor Matos
Source:
Chapter 5, “The Theory of Relational Databases”, D. Maier, Ed. Comp. Sc. Press,
1983 ISBN 0-914894-42-0.
1
Cleveland State University
Agenda
1. Covers and Equivalence
2. Non-redundant covers
3. Extraneous attributes
4. Canonical covers
5. Minimum covers
2
3/23/2010
2
Introduction
In this section we will explore ways of
representing FDs in a concise mode
Reducing the size of a set of FDs benefits
the computation of closures and other
related algorithms
Reduced sets of FDs help ensure database
consistency and correctness
3
Overview
The overall strategy is to minimize the set
of FDs for a given relational schema in
order to – (1) save storage and,
– (2) reduce the number of compliance-tests performed
when the database records are modified
Optimization is done by throwing away
unwanted rules and unneeded attributes
4
3/23/2010
3
Example
Consider the database schema R(ABC) under the set
F1 = {A → B, B → C, A → C, A B → C, A → B C }
Again, the same database schema R(ABC) but the set
F2 = {A → B, B → C }
It is easy to see that F1 and F2 are equivalent.
Using the more compact set F2 will provide a better
representation of the semantic of data in R(ABC) as
well as better performance/storage.
5
1. Covers and Equivalences
Two sets of FDs F1 and F2 over scheme R
are equivalent , written F1 F2 if F1+ = F2
+
If F1 F2 then F1 is a cover for F2
Example: The sets
F1= { AB → C, A → D, CD → E } and
F2= { A → BCE, A → ABC, CD → E }
are NOT equivalent
6
3/23/2010
4
Example
Consider the schema R(ABCDE) and the sets of FDs F1,
F2 and F3 listed below
F1= { A → BC, A → D, CD → E }
F2= { A → BCE, A → ABD, CD → E }
F3= { A → BCDE }
By observation of the sets we conclude that:
– F1 and F2 are equivalent (A+ =ABCDE, CD+ = CDE in both sets)
– F1 and F3 are not equivalent ( F1F3, but F3 cannot imply CD→E)
7
Observation
A mechanical way of testing if F1 F2 is to
simply compare F1+ and F2
+
However:
Computing the closure F+ of a set of FDs is time
consuming.
We need a ‘better’ way of working (other than the
brute-force generation of all the possible
derivation sequences)
8
3/23/2010
5
Member Function
Determine if a single FD X →Y is derived from a set F of FDs
Input: A set of FDs and an FD X →YOutput: true if FX →Y, false otherwise
Member(F, X →Y)
beginif ( XF
+ Y )
then return (true)
else return (false);
end
9
Lemma
Given sets F1 and F2 over schema R, F1 F2 if and only if F1F2 and F2 F1
Function DERIVES ( F1, F2)
Input: Two sets of FDs F1 and F2
Output: true if F1 F2, false otherwise
begin
v = true;
for each FD X Y in F2 do
v = v and Member ( X Y, F1 );
return ( v );
end10
3/23/2010
6
Input: Two sets of FDs F1 and F2
Output: true if Fl F2, false otherwise
Function EQUIV ( Fl , F2)
v = DERIVES (F1 ,F2) and DERIVES ( F2, Fl);
return ( v );
end
How to check that two sets of dependencies are
equivalent ?
11
Example: Consider the schema R(ABCDE) and the sets of
FDs F1 and F2 listed below
F1 = {A → B, B → C, A → C, A B → C, A → B C }
F2 = {A → B, B → C }
Observations:
1. Each dependency in F2 is in F1, therefore F1 DERIVES F2 .
2.1 Rule A → C in F1 is a member of F2
2.2 Rule A B → C in F1 is a member of F2
2.3 Rule A → B C in F1 is a member of F2
2.4 Therefore all dependencies in F1 are DERIVED from F2.
3. According to the EQUIV function F1 and F2 are equivalent.
How to check that two sets of dependencies are
equivalent ?
12
3/23/2010
7
A set F1 of FDs is non-redundant if there is no proper sub-set F' of F1 such that Fl F'
If such an F' exists then F1 is redundant.
F1 is a non-redundant cover for F2 if1. F1 is a cover for F2 (F1 F2), and
2. F1 is a non-redundant set of FDs.
Redundant Covers
13
Example. Universe is {A, B, C }. There are
three set of FDs
Fl= { AB →C, A → B, B → C, A → C }
F2 = {AB → C, A → B, B → C }
F3 = {A → B, B → C }
Observations
1. F1 is a redundant cover for F2
2. F3 is a non redundant cover for F2
Redundant Covers
14
3/23/2010
8
EXAMPLE:
Let R(ABC) and F= { A → B, B → A, B → C, A → C }
Observe that rule A → C is redundant. It could be obtained
by applying transitivity on A → B and B → C.
Therefore
F2 = { A → B, B → A, B → C } is a cover for F (it also
happens to be non-redundant).
1. Testing RedundancyHow to eliminate a rule X→Y from a set of FDs ?
15
ALGORITM NonRedundant (F1)
Input: An arbitrary set F1 of FDs
Output: A non-redundant cover F2 for F1
begin
F2 = F1;
for each FD X→ Y in F1 do
if Member(X → Y, F2 - (X → Y) )
then F2 = F2 - ( X → Y );
return ( F2 );
end;
2. Testing RedundancyHow to eliminate a rule X→Y from a set of FDs ?
16
3/23/2010
9
EXAMPLE:
Let R(ABC) and F= { A → B, B → A, B → C, A → C }
After applying the previous function we obtain:
F2 = F – {A → C } = { A → B, B → A, B → C }
is a non-redundant cover for F.
3. Testing RedundancyHow to eliminate a rule X→Y from a set of FDs ?
17
Let F be a set of FDs over schema R, and let X→Y be an FD
in F. Attribute A in R is extraneous in the rule X → Y if
either
LEFT. Assume X = A Z , X Z and
F ( F - { X → Y } ) { Z → Y }
RIGHT. Assume Y = AW, YW and
F ( F - {X →Y} ) {X →W}
Extraneous AttributesOur intention is to discard from F unnecessary attributes appearing
in individual FDs without changing the closure of F.
18
3/23/2010
10
Example
Consider schema R = { A, B, C, D } and FDs
F = { A → BC, B → C, AB → D }
Left Reduction. We look for FDs having more than one attribute on the
LHS. The only candidate is: AB → D
(1). Extract A from AB → D
(2). If (1) didn‟t work try taking B from AB → D
Right Reduction. Look for FDs with more than one attribute on the RHS.
The only candidate is: A → BC
(3). Try removing B from A → BC
(4). If (3) didn‟t work try deleting C from A → BC
Extraneous Attributes
19
Input: A set G of FDs
Output: A left-reduced cover F for G
begin
F=G;
for each X → Y in G do
for each attribute A in X do
if Member (X-A → Y, F) then {
Remove A from X in X → Y;
Update F adding new rule X-A → Y;
}
return( F );
end;
Algorithm: LeftReduction (G)
20
3/23/2010
11
Input: A set G of FDs
Output: A right-reduced cover F for G
begin
F=G;
for each X → Y in G do
for each attribute A in Y do
if Member(X → Y, F-{X → Y}U {X → Y-A} ) {
Remove A from Y in X → Y;
Update F adding new rule X → Y-A
}
return( F );
end;
Algorithm: RightReduction (G)
21
Consider the relation schema R subject to F
1. Create set F' by removing extraneous attributes
in the following order: first do left then right
reductions
2. Remove redundant functional dependencies.
3. The new set (R,F' ) is called a Canonical Cover
for (R, F)
Canonical CoverConstructing a „better‟ representation of F
22
3/23/2010
12
Example Let r(ABCDIJM) be subject to the FDs
F= { A → C, AC → J, AB → DE, AB → CDI, C → M, A → M }
(a) Left reduction
1. Test rule AC → J. Drop A, to make C → J. New set F2 is not
equivalent to F ( Member (AC → J, F2) = false ). Therefore A can
not be eliminated.
2. Try dropping C from AC → J. Make F2= F-{AC → J) + {A → C).
F2 is equivalent to F ( Member (AC+ J, F2) = true ). Consequently C
can be eliminated from AC → J.
(b) Right reduction.
1. Attribute D in AB → DE is redundant, and
2. Attribute C in AB → CDI is redundant, eliminate both.
(c ) Redundant Rules. Eliminate rule A → M
(d) Result: F= { A → CI, AB → EDI, C → M }
Canonical Covers
23
Example. Let r(ABC) be subject to the FDs
F= { A → BC, B → C, A → B, AB → C }
(a) Left reduction.
(b) Right reduction.
(c) Redundant Rules.
(d) Result ?
Canonical Covers
Your turn …
24
3/23/2010
13
Observation: A schema R could have more than one non-
redundant cover. Our next goal is to explore the similarities
between them.
Definition
Two sets of attributes X and Y are equivalent under FDs F, written X ↔Y, if F XY and F YX.
Lemma. Given equivalent, non-redundant covers F and G,
for every left side X of an FD in F there is an equivalent left
side V of an FD in G.
The Structure of Non-Redundant Covers
25
Example:
Let R(ABCDE) and FD sets
F = { A→BC, B→A, AD→E } and
G= { A → ABC, B → A, BD → E }Notice that
EF(A) = {A→BC, B→A } (observe that AF+= BF
+ = ABC)
EF(B) = {A→BC, B→A }
EF(AD) = { AD→E } (observe ADF+= ABCDE)
EG(A) = {A→BC, B→A } (observe that AG+= BG
+ = ABC)
EG(B) = {A→BC, B→A }
EG(BD) = { BD→E } (observe BDG+= ABCDE)
F and G are non-redundant and equivalent to each other (non redundant in the sense
that rules can not be removed, however there are superfluous attributes in G).
Observe that: AF ↔ AG , BF ↔ BG and ADF ↔ BDG
The Structure of Non-Redundant Covers
26
3/23/2010
14
Definition. Equivalent Classes
For a set of FDs F over scheme R and a set X R, let EF(X) be the set of
FDs in F with left sides equivalent to X.
Let E F be the set { EF(X) / X R and EF(X) Ø }
E F(X) is empty when no left side of any FD in F is equivalent to X.
E F is always a partition of F.
Example: Consider the previous example.
The Structure of Non-Redundant Covers
E F E G
EF(A) = {A→BC, B→A}
EF(B) = EF(A)
EF(AD) = {AD→E }
EG(A) = {A→ABC, B→A}
EG(B) = EG(A)
EG(BD) = {BD→E }
F = { A→BC, B→A, AD→E } and
G= { A → ABC, B → A, BD → E }
27
Example: Consider the non-redundant set of FDs
F = { A→BC, B→A, AD→E, BD→I }
Let‟s find all the equivalent classes of F.
Find closures of left-hand-sides:
• A+ = ABC
• B+ = ABC same, therefore EF(A) = EF(B) = {A→BC, B→A }
• (AD)+ = ABCDEI
• (BD)+ = ABCDEI same EF(AD) = EF(BD) = { AD→E, BD→I }
Therefore
E F = { EF(A), EF(AD) }
The Structure of Non-Redundant Covers
28
3/23/2010
15
Observation. A non-redundant cover of a set G of
FDs does not necessarily have as few FDs as any
cover for G.
Definition. A set of FDs F is minimum if F has as
few FDs as any equivalent set of FDs.
A minimum set of FDs is also non-redundant.
Minimum Cover
29
Example.
The set G is non-redundant but not minimum, since F is
equivalent to G but has fewer FDs.
F is a minimum cover for G.
(observe that G is already a Canonical cover)
G = { A→BC, B→A, AD→E, BD → I }
F = { A→BC, B→A, AD→E I }
Minimum Cover
30
3/23/2010
16
Unlike non-redundant covers, the definition of minimum covers provides
no guide for finding minimum covers or even for testing minimality.
The next concept on direct functional determination gives us the means to
compute minimum covers.
Definition. Given a set of FDs G, X directly determines Y under G, written X Y, if there is a non-redundant cover F for G with an F-based
DDAG H for X→Y such that U(H) ∩ EF(X) = Ø.
In other words, we can find a non-redundant cover F for G in which X→Y
can be derived using only FDs in { F - EF(X) }.
Observe that X X always holds, that X Y implies X→Y, and that
EF(X) can be empty.
Direct Determination
31
Re-phrasing
Definition. Given a set of FDs G, X directly determines Y under G, written X Y, if there is a non-redundant cover F for G with an F-based
DDAG H for X→Y such that U(H) ∩ EF(X) = Ø.
Equivalent to :
X Y if { F – EF(X) } X→Y
Direct Determination
32
3/23/2010
17
Example. Let G = F = { A→CD, AB→E, B → I, DI → J }.Then AB J under G, as the DDAG H in next figure shows.
Here the „use set‟ for the DDAG H drawn for AB →J is:
U(H) = { A→D, B → I, DI → J } and
Observe that
EF(AB) = { AB → E }
Their intersection is empty, therefore AB J
Direct Determination
A D
B I
J
33
Example.
Let F = {A → BC, BC → A, AD→E, AD → I, E→B }.
Observe that BCD ↔ A D ( observe that BCD+=AD+=ABCDEI )
Figure below shows an F-based DDAG for BCD→AD that uses no FDs
from EF(AD) and no FDs in EF(BCD).
U(H) = { BC → A }EF(BCD) = ØEF(AD) = { AD→E, AD→I }
observe that U(H) EF(BCD) = U(H) EF(AD) =Ø therefore BCD ADsimilarly AD BCD
Computing Minimum Covers
B
D
C
A
34
3/23/2010
18
Theorem. Let F be a non-redundant set of FDs that is not minimum.
There is some EF(X) containing distinct FDs Y→U and Z→V such thatY Z.
Observation
We know the set F = { A→BC, B→A, AD→E, BD → I } is non-redundant,
and we have computed its equivalence classes already.
EF(A) = EF(B) = {A→BC, B→A } and
EF(AD) = EF(BD) = { AD→E, BD→I }
Consider the set EF(BD). According to previous theorem AD BD as well as
BDAD. See the DDAG and its use set for BD → AD
Use set U(H) = { B→A }notice that U(H) ∩ EF(BD) = Øtherefore BDAD
Computing Minimum Covers
35
Observation (continuation…)
Therefore the non-redundant cover
F = { A→BC, B→A, AD→E, BD → I } is not a minimum set.
As we will see it could be reduced to the smaller minimum cover
F2 = { A→BC, B→A, BD→EI }
or equivalently
F3 = { A→BC, B→A, AD→EI }
Computing Minimum Covers
36
3/23/2010
19
Algorithm. MINIMIZE
Input: A set of FDs G.
Output: A minimum cover for G.
MINIMIZE(G)
begin
F : = NONREDUN(G);
Find the sets of EF
for each EF(X) in EF do
for each Y → M in EF(X) dofor each Z → V Y → M in EF(X) do
If DDERIVES(F, Y → Z) then
replace Y → M and Z → V by Z → MV in F,
return(F)
end.
MINIMIZE can be implemented to have time complexity O(np) on inputs of length n with p FDs.
Computing Minimum Covers
37
Example
Set F = { A→BC, B→A, AD→E, BD → I } from previous examples is
known to be non-redundant, we also have computed its equivalence classes:
EF(A) = EF(B) = {A→BC, B→A } and
EF(AD) = EF(BD) = { AD→E, BD→I }
MINIMIZE algorithm will consider the set EF(A) and conclude that neither
A B nor BA holds.
However, when working with the set EF(AD) the MINIMIZE algorithm will discover that BDAD and AD BD. Therefore the rules
{AD→E, BD→I} will be re-written as {AD→EI}.
This contraction will reduce the set F to a minimum cover
F2 = { A→BC, B→A, AD→EI }
Computing Minimum Covers
38
3/23/2010
20
David Maier, "The Theory of Relational Databases", Comp. Sc. Press,
1983.
H. Mannila, K. Raiha, “The Design of Relational Databases”. Addison-
Wesley, 1992.
Elmasri, Navathe, “Fundamentals of Database Systems”, 5th Ed.
Addisson-Wesley, 2007.
Silberschatz, Korth, Surdarshan, “Database System Concepts”, McGraw-
Hill, 2011
Where to get more information?
39