0% found this document useful (0 votes)
22 views28 pages

550 Lecture15

The document discusses the properties and implications of decomposing a relation schema in database design, emphasizing the importance of lossless join and dependency preserving decompositions. It outlines potential problems that may arise from decompositions, such as increased query costs and challenges in reconstructing original relations. Additionally, it explains the concept of minimal covers for functional dependencies, providing methods for finding them and ensuring efficient database design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views28 pages

550 Lecture15

The document discusses the properties and implications of decomposing a relation schema in database design, emphasizing the importance of lossless join and dependency preserving decompositions. It outlines potential problems that may arise from decompositions, such as increased query costs and challenges in reconstructing original relations. Additionally, it explains the concept of minimal covers for functional dependencies, providing methods for finding them and ensuring efficient database design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Lecture 15

Properties of Decompositions
Decomposition of a Relation
Schema
• A decomposition of R consists of replacing R by
two or more relations such that:
– Each new relation schema contains a subset of the
attributes of R, and
– Every attribute of R appears as an attribute of one or
more new relations
• Store instances of the relation schemas produced
by the decomposition, instead of instances of R
• Decompositions should be used only when
needed
Decomposition Example
• Consider a relation obtained from Hourly_Emps:
– Hourly_Emps (ssn, name, lot, rating, hrly_wages, hrs_worked)
– Denote this relation schema by listing the attributes: SNLRWH
– SNLRWH has FDs: S ® SNLRWH and R ® W
– R ® W causes violation of 3NF
– Create a relation RW to store the associations and remove W
from the main schema (decompose SNLRWH into SNLRH and
RW)
• If we just store the projections of SNLRWH tuples onto
SNLRH and RW, are there any potential problems that we
should be aware of?
Problems with Decompositions
• Three potential problems:
1. Some queries become more expensive
• e.g., How much did sailor Joe earn? (salary = W*H)
2. Given instances of the decomposed relations, we
may not be able to reconstruct the corresponding
instance of the original relation!
3. Checking some dependencies may require joining the
instances of the decomposed relations
• Tradeoff: must consider these issues vs.
redundancy
Problem 2: Example
A B
1 2
A B C 4 5
1 2 3 7 2
4 5 6
B C
7 2 8
2 3
5 6
2 8
A B C
1 2 3
4 5 6
7 2 8
1 2 8
7 2 3
Lossless Join Decomposition
• Decomposition of R into X and Y has the
lossless-join property w.r.t. a set of FDs F if
for every instance r of R that satisfies F:
p X (r ) !" p Y (r ) = r
• It is always true that r Í p X (r ) !" p Y (r ). If the
other direction holds, the decomposition is
lossless-join
• Definition extends to decomposition into 3
or more relations
Lossless Join Decomposition (Cont.)

• Repeated decompositions: R is decomposed


into R1 and R2 through a lossless join
decomposition, and R1 is decomposed into R11
and R12 through another lossless join
decomposition. Then the decomposition of R
into R11, R12, and R2 is lossless join
• All decompositions used to deal with
redundancy should be lossless! (Avoids problem
2)
Testing Binary Decomposition for
Lossless Join
• R1, R2 is a lossless join decomposition of R
with respect to F iff at least one of the
following dependencies is in F+(the closure
of F)
– (R1 Ç R2) ® R1
– (R1 Ç R2) ® R2
• For example, the decomposition of R into
UV and R - V is lossless if U ® V holds
over R
Example
Id# Name Address C# Description Grade
124 Jones Phila Phil7 Plato A
789 Brown Boston Math8 Topology C
• Given the FD set:
Id# ® Name, Address
C# ® Description
Id#, C# ® Grade
• Is (Id#, Name, Address) and (Id#, C#,
Description, Grade) a lossless decomposition?
• What happens if we decompose on (Id#, Name,
Address) and (C#, Description, Grade)?
Dependency Preserving
Decomposition
• Consider a relation: Contracts (contractid,
supplierid, projectid, deptid, partid, qty, value)
– CSJDPQV, C is the key, JP ® C and SD ® P
– BCNF decomposition: CSJDQV and SDP
– Problem: Checking JP ® C requires a join!

• If R is decomposed into X, Y and Z through a


dependency preserving decomposition, and if we
enforce the FDs that hold on X, on Y and on Z,
then all FDs that were given to hold on R must
also hold. (Avoids problem 3)
Dependency Preserving
Decomposition (Cont.)
• Suppose we need to update a relation in a database.
Can we easily check whether an FD X®Y is violated?
– We can if X È Y is contained within the set of attributes
• The projection of an FD set F onto a set of attributes Z
FZ = {X®Y | X®YÎF+ and X ÈY ÎZ}
• A decomposition R1, …, Rk is dependency preserving if
F+ = (FR1 È...È FRk)+
• Dependency preserving decomposition hasn’t “lost” any
essential FDs
Dependency Preserving
Decompositions (Cont.)
• Decomposition of R into X and Y is dependency
preserving if (FX È FY )+ = F+
– i.e., if we consider only dependencies in the closure F+ that can be
checked in X without considering Y, and in Y without considering
X, these imply all dependencies in F+
• Important to consider F+, not F
– ABC, A ® B, B ® C, C ® A, decomposed into AB and BC
– Is this dependency preserving? Is C ® A preserved?
• Dependency preserving does not imply lossless join and
vice versa!
– ABC, A ® B, decomposed into AB and BC
Example 1
• Given a relation schema: {Sname, Sadd, City,
Zip, Item, Price} and an FD set:
– FD1: Sname ® Sadd, City
– FD2: Sadd, City ® Zip
– FD3: Sname, Item ® Price
• Consider the decomposition: {Sname, Sadd, City,
Zip} and {Sname, Item, Price}
– Is it lossless?
– Is it dependency preserving?
– What if we replaced FD1 by Sname, Sadd ® City ?
Example 2
• Given a relation schema {Student, Teacher,
Subject} and an FD set
– FD1: Teacher ® Subject
– FD2: Student, Subject ® Teacher
• Consider the decomposition: {Student, Teacher}
and {Teacher, Subject}
– Is it lossless?
– Is it dependency preserving?
Minimum Sets of Functional
Dependencies
Equivalence of FD Sets
• Two sets of FDs, F and G, are equivalent
if F+ = G+
• Example: {AB ® C, A ® B } and {A ® C,
A® B } are equivalent
• F+ contains a huge number of FDs
(exponential in the size of the schema).
One naturally looks for small equivalent
• A set of FDs F covers another set of FDs
E if every FD in E is also in F+
Minimal Cover
• Minimal cover G for a set of FDs F:
– F+ = G+
– RHS of each FD in G is a single attribute
– If we modify G by deleting an FD or by deleting
attributes from an FD in G, the closure changes
• Every FD in minimal cover G is needed, and “as
small as possible” in order to get the same
closure as F
– e.g., {A ® B, ABCD ® E, EF ® GH, ACDF ® EG} has
a minimal cover: {A ® B, ACD ® E, EF ® G, EF ® H)
Minimal Cover (Cont.)
• Formal Definition: A FD set F is minimal if
1. Every FD in F is of the form X ® A, where A is a
single attribute
2. No redundant attributes from LHS of FDs
3. No redundant FDs
• Every dependency is required and is as small as
possible
– Each attribute on the left side is necessary
– Right side is a single attribute
• Example:
{A ® C, A® B} is a minimal cover for {AB ® C, A ® B}
Finding a Minimal Cover
1. Replace each functional dependency
X ® {A1, A2,…, An} in F by the n
functional dependencies X ®A1, X
®A2,…, X ®An
2. Remove all redundant attributes from
LHS of FDs
3. Remove all redundant FDs
Example
Find a minimal cover for {ABH ® C, A ® D, C ® E, BGH ®
F, F ® AD, E ® F, BH ® E}

Step1: RHS are single attribute. Applying decomposition rule:


ABH ® C, A ® D, C ® E ,BGH ® F, F ® A , F ® D, E ® F, BH ® E

Step2: Remove redundant attributes from LHS:


BH ® C (BH)+ (BEH) (BEFH) (ABEFH) (ABCEFH)
BH ® E E ® F F®A ABH ® C
A®D
C®E
BH ® F
F®A
F®D
E®F
BH ® E
Example (Cont.)
Step 3: Remove redundant FDs: BH ® F, F ® D,
and BH ® E since:
BH ® F can be derived from BH ® C, C ® E, E ® F
F ® D can be derived from F ® A, A ® D
BH ® E can be derived from BH ® C, C ® E

A minimal cover is
{BH ® C, A ® D, C ® E, F ® A, E ® F}
Exercise
• Find a minimal cover for {B ®A, D ®A, AB ®D}
• Find a minimal cover for {A ® B, ABCD ®E, EF
®G, EF ®H, ACDF ®EG}

You might also like