You are on page 1of 28

Decomposition

Decomposition
 Decompose a relation schema that has many
attributes into several schemas with fewer
attributes
 Let R be a relation schema
A set of relation schemas { R1, R2,…, Rn } is a
decomposition of R if

 R = R1 U R2 U …..U Rn
 each Ri is a subset of R ( for i = 1,2…,n)
 But careless decomposition may lead to bad
form of a design
For relation R(x,y,z) there can be 2 subsets:
R1(x,z) and R2(y,z)
E If we union R1 and R2, we get R
X
A
R = R1 U R2
M
P Decomposition
L
E

Loss Less Join Lossy Join


Decomposition Decomposition
Lossy Decomposition
Model Name Price Category
R
a11 100 Canon
s20 200 Nikon
a70 150 Canon

R1 R2
Model Name Category Price Category

a11 Canon 100 Canon


s20 Nikon 200 Nikon
a70 Canon 150 Canon

Model name Category


Price  category
Model Name Price Category
a11 100 Canon
R1 U R2 a11 150 Canon
s20 200 Nikon
a70 100 Canon
a70 150 Canon

Model Name Price Category

But main a11 100 Canon


R is
s20 200 Nikon
a70 150 Canon
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
Lossy Decomposition
T
Employee Project Branch
E Brown Mars L.A.
X Green Jupiter San Jose
A Green Venus San Jose

M Hoskins Saturn San Jose


Hoskins Venus San Jose
P
L
Functional dependencies:
E
Employee Branch,
Project Branch
T1 T2

Employee Branch Project Branch


Brown L.A Mars L.A.

Green San Jose Jupiter San Jose

Hoskins San Jose Saturn San Jose


Venus San Jose

Employee Project Branch


Brown Mars L.A.
Green Jupiter San Jose
T1 U T2
Green Venus San Jose
Hoskins Saturn San Jose
Hoskins Venus San Jose
Green Saturn San Jose
Loss info
Hoskins Jupiter San Jose
Lossless Decomposition
 A decomposition {R1, R2,…, Rn} of a relation R is
called a lossless decomposition for R if the join of R1,
R2,…, Rn produces exactly the relation R.
 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
Model Name Price Category
a11 100 Canon
E R s20 200 Nikon
X
a70 150 Canon
A
M
P
R1 R2
L
E Model Name Price Model Name Category

a11 100 a11 Canon

s20 200 s20 Nikon


a70 150 a70 Canon
Lossless Decomposition Property
R : relation
F : set of functional dependencies on R
R1,R2 : decomposition of R
Decomposition is lossles if :
◦ R1 ∩ R2  R1, that is: all attributes common to both R1
and R2 functionally determine ALL the attributes in R1
OR
◦ R1 ∩ R2  R2, that is: all attributes common to both R1
and R2 functionally determine ALL the attributes in R2
R = (A, B, C, D, E)

R1 = (A, B, C) R2 = (A, D, E)
E The set of functional dependencies:
X A → BC, CD → E, B → D, E → A

A 1. R1 ∩ R2 = A;
M
P 2. Compute A+
(A → BC)
L (A → ABC)
E A ABCD
(A → ABCDE)

Here A contains all attributes which follows R1 and R2 relation

(R1 ∩ R2 → R1) , (R1 ∩ R2 → R2 ) Lossless-join decomposition


R = (A, B, C, D, E)

E R1 = (A, B, C) R2 = (A, D, E)
The set of functional dependencies is:
X
A → BC, E → A
A
M 1. R1 ∩ R2 = A;
P
2. Compute A+
L
(A → BC)
E (A → ABC)

Here A contains all attributes which follows R1 relation

(R1 ∩ R2 → R1) this is a lossless-join decomposition


Dependency Preservation
 Getting lossless decomposition is necessary so
we need to get relations which contains all
existing functional dependency or preserve
dependencies

 A decomposition D = {R1, R2, ..., Rn} of R is


dependency-preserving with respect to F if the
union of the projections of F on each Ri in D is
equivalent to F; that is
if (F1  F2  …  Fn )+ = F +
Example of Dependency Preservation
R(A B C D)

FD1: AB
FD2: BC
FD3: CD

Decomposition:
R1(A B C) R2(C D)
FD1: AB
FD2: BC
FD3: CD

R 1( A B C )
FD1

FD2
FD1: AB
FD2: BC
FD3: CD

R2( C D )
FD3
FD1: A B
FD2: BC
FD3: CD

R1( A B C ) R2( C D )
FD1 FD3

FD2

Has all 3 functional dependencies of given


relations is preserved from R1 and R2.
Therefore, it’s preserving the dependencies
Example of Non-Dependency Preservation
R(A B C D)

FD1: AB
FD2: BC
FD3: CD

Decomposition:
R1(A C D) R2(B C)
FD1: AB
FD2: BC
FD3: CD

R1( A C D )
FD3
FD1: AB
FD2: BC
FD3: CD

R2( B C )
FD2
FD1: A B
FD2: BC
FD3: CD

R1( A C D ) R2( B C )
FD3 FD2

Does not support FD1: A => B


Therefore, it does not preserve the dependencies
More Example
R(A B C D E)

FD1: AB
FD2: BC  D

Decomposition:
R1(A C E) R2(B C D)
R3(A B)
FD1: AB
FD2: BC  D

R1( A C E )
No Dependencies
FD1: AB
FD2: BC  D

R2( B C D )
FD2
FD1: AB
FD2: BC  D

R 3( A B )
FD1
FD1: AB
FD2: BC  D

R1( A C E )R2( B C D )
FD2
R3( A B )
FD1

Has all 2 functional dependencies!


Therefore, it’s preserving the dependencies

You might also like