8 part B Relational Database Design
8 part B Relational Database Design
12
Lossless Join Decomposition
R1, … Rk is a lossless join decomposition of R w.r.t. an FD set F if
for every instance r of R that satisfies F,
R1(r) ⋈ ... ⋈ Rk(r) = r
Consider:
sid name serno subj cid exp-grade
What if we decompose on
(sid, name) and (serno, subj, cid, exp-grade)?
13
Example of Lossy Decomposition
Problem with Decomposition
• Given instances of the decomposed relations,
we may not be able to reconstruct the
corresponding instance of the original relation
– information loss
Lossy decomposition
• In previous example, additional tuples are
obtained along with original tuples
• Although there are more tuples, this leads to
less information
• Due to the loss of information, decomposition
for previous example is called lossy
decomposition or lossy-join decomposition
Lossless Decomposition
A decomposition {R1, R2,…, Rn} of a relation R
is called a lossless decomposition for R if the
natural join of R1, R2,…, Rn produces exactly
the relation R.
Lossless Decomposition
A decomposition is lossless if we can recover:
R(A, B, C)
Decompose
R1(A, B) R2(A, C)
Recover
R’(A, B, C)
Thus, R’ = R
Lossless Decomposition Property
R : relation
F : set of functional dependencies on R
X,Y : decomposition of R
Decomposition is lossles if :
– X ∩ Y X, that is: all attributes common to both X and Y
functionally determine ALL the attributes in X OR
– X ∩ Y Y, that is: all attributes common to both X and Y
functionally determine ALL the attributes in Y
Testing 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+
(R1 R2) R1
(R1 R2) R2
So for the FD set:
sid name
serno cid, exp-grade
cid subj
20
Lossless Decomposition Property
• In other words, if X ∩ Y forms a superkey of either
X or Y, the decomposition of R is a lossless
decomposition
Example
R(A1, A2, A3, A4, A5)
F = { A1 A3 A5,
A5 A1 A4,
A3 A4 A2 }
decomposed into
R1 (A1, A2, A3, A5)
R2 (A1, A3, A4)
R3 (A4, A5)
Example (con’t)
A1 A2 A3 A4 A5
R1 a(1) a(2) a(3) b(1,4) a(5)
R2 a(1) b(2,2) a(3) a(4) b(2,5)
R3 b(3,1) b(3,2) b(3,3) a(4) a(5)
Example (con’t)
By FD1: A1 A3 A5
A1 A2 A3 A4 A5
R1 a(1) a(2) a(3) b(1,4) a(5)
R2 a(1) b(2,2) a(3) a(4) b(2,5)
R3 b(3,1) b(3,2) b(3,3) a(4) a(5)
Example (con’t)
By FD1: A1 A3 A5
we have a new result table
A1 A2 A3 A4 A5
R1 a(1) a(2) a(3) b(1,4) a(5)
R2 a(1) b(2,2) a(3) a(4) a(5)
R3 b(3,1) b(3,2) b(3,3) a(4) a(5)
Example (con’t)
By FD2: A5 A1 A4
A1 A2 A3 A4 A5
R1 a(1) a(2) a(3) b(1,4) a(5)
R2 a(1) b(2,2) a(3) a(4) a(5)
R3 b(3,1) b(3,2) b(3,3) a(4) a(5)
Example (con’t)
FD2: A5 A1 A4
we have a new result table
A1 A2 A3 A4 A5
R1 a(1) a(2) a(3) a(4) a(5)
R2 a(1) b(2,2) a(3) a(4) a(5)
R3 a(1) b(3,2) b(3,3) a(4) a(5)
Conclusions
• Decompositions should always be lossless
Lossless decomposition ensure that the
information in the original relation can be
accurately reconstructed based on the
information represented in the decomposed
relations.
Dependency Preservation
Ensures we can “easily” check whether a FD X Y
is violated during an update to a database:
31
Example of Decompositions in BCNF but
not Dependency-Preserving
Given relation scheme
R(sailorid, boatid, date)
Sailorid, boatid->date
(a sailor can reserve a boat for atmost one day)
Date->boatid
(on a give day at most one boat can be reserved)
36
Summary
We can always decompose into 3NF and get:
Lossless join
Dependency preservation
37
Fifth normal form (5NF):
Projection-Join Normal form
5NF is related to join dependency, which is the
term used to indicate the property of a relation
scheme that cannot be decomposed losslessly
into two simpler relation schemes, but can be
decomposed losslessly into three or more
simpler relation schemes.
5NF(Projection join normal form)
q1.Display the list of employees having project p2.
prob: E2 is displayed twice.
q2. Display the projects under the manager M1
prob:P1 is displayed twice.
q3. Display the managers of project P2.
prob: M2 is displayed twice.
q4.Display the employees working under M1
prob:E3 is displayed twice
Employee Project
no. no.
E1 P1
E1 P2
E2 P2
E3 P1
E3 P3
5NF(Projection join normal form)
Project Manager
no. no.
P1 M1
P2 M2
P2 M4
P3 M1
5NF(Projection join normal form)
Employee Manager
no. no.
E1 M1
E1 M2
E2 M2
E2 M4
E3 M1
These dependencies are the translation of the enterprise’s need that the employees
involved in a given project must have certain expertise. Because of the expertise of
employees, they want to be involved in a given set of projects whose requirements
match their interests.
The expertise of an employee, not needed for
any project to which he or she is assigned, is
not shown in this relation.
• Suppose Smith has expertise in AI as well. As there is no
project in the tables that needs AI, such info was never stored.