Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 35

Decomposition

Decomposition
• In a database, it breaks the table into multiple
tables. If the relation has no proper
decomposition, then it may lead to problems
like loss of information.
• Decomposition helps in eliminating some of
the problems of bad design such as
redundancy, inconsistencies and anomalies.
Undesirable Properties of Bad Design

• Redundancy, resulting in waste of space


and complicated updates
(inconsistencies.)
• Inability to represent certain information
– ex Null values.
• Loss of information.
Decomposition

• There are careless, “bad” decompositions.


• There are three desirable properties:
1. Lossless.
2. Dependency preservation.
3. Minimal redundancy.
1. Lossless Join Decomposition

• One of the properties of bad design suggests to


decompose a relation into smaller relations.
• Must achieve lossless-join decomposition.
1. Lossless Join Decomposition

• Definition:
– Let { R1, R2 } be a decomposition of R
(R1 U R2 = R); the decomposition is
lossless if for every legal instance r of R:
r = ΠR1(r) |X| ΠR2(r)
1. Lossless Join Decomposition
1. Lossless Join Decomposition
1. Lossless Join Decomposition
1. Lossless Join Decomposition
Testing Lossless Join
• Lossless join property is necessary if the decomposed relation
is to be recovered from its decomposition.
• Let R be a schema and F be a set of FD’s on R, and α = (R1,
R2) be a decomposition of R. Then α has a lossless join with
respect to F iff
R1 ∩ R2 -> ( R1 - R2 ) or
R2 ∩ R1 -> ( R2 - R1 )
where such FD exist in Closure of F
This is a sufficient condition, but not a necessary
condition.
Example of L-J Decomposition
From the previous example : R = (ABC) F = {A -> B}, {A -> C}
R1 = (AB), R2 = (AC)
R1∩ R2 = A, R1- R2 = B
R2∩ R1 = A, R2- R1 = C
check A -> B in F ? A->C ? Yes. Therefore lossless

R1 = (AB), R2 = (BC)
R1∩ R2 = B, R1 - R2 = A , R2 - R1= C
check B -> A in F ? NO
check B -> C in F ? NO
So, this is lossy join.
Another example

R = (City, Street, Zip) F = {CS -> Z, Z -> C}

R1 = (CZ) R2 = (SZ)
R1 ∩ R2 = Z , R1 – R2 = (C)
check Z -> C in F ? Yes

Therefore, the decomposition to be (CZ) (SZ) is


lossless join decomposition.
2. Dependency-Preserving Decomposition

• The dependency preservation decomposition


is another property of decomposed relational
database schema D in which each functional
dependency X -> Y specified in F either
appeared directly in one of the relation
schemas Ri in the decomposed D or could be
inferred from the dependencies that appear in
some Ri.
• Decomposition D = { R1 , R2, R3,,.., ,Rm} of R is said
to be dependency-preserving with respect to F if
the union of the projections of F on each Ri , in D
is equivalent to F. In other words, R ⊂  join of R1,
R1 over X. The dependencies are preserved
because each dependency in F represents a
constraint on the database. If decomposition is
not dependency-preserving, some dependency is
lost in the decomposition.
• Example:
Let a relation R(A,B,C,D) and set a FDs F = { A -> B ,  A -> C  ,
C -> D}  are given.
A relation R is decomposed into -
 
R1 = (A, B, C) with FDs F1 = {A -> B, A -> C}, and
R2 = (C, D) with FDs F2 = {C -> D}.
F' = F1 ∪ F2 = {A -> B, A -> C, C -> D}
so, F' = F.
And so, F'+ = F+.
Dependency Preservation Decomposition

• Definition: Each FD specified in F either appears directly in


one of the relations in the decomposition, or be inferred from
FDs that appear in some relation.
Dependency Preserving Example
• Consider relation R(ABCDE), with FD’s
• F= A ->B, B->C, C ->D, D ->A
• R1(A,B,C) R2=(C,D,E)
• All the original dependencies are preserved or not.
• R1(A,B,C)
A+ = ABCD A->BC
B+ = BCDA B->CA
C+ = CDAB C->AB
AB+ =ABCD AB->C (Redundant = A->BC) So omitted
BC+=BCDA BC->A (Redundant = B->CA) So omitted
AC+=ACBD AC->B (Redundant = A->BC) So omitted
F1 = { A->BC, B->CA, C-> AB}
Dependency Preserving Example
• R2=(C,D,E)
• C+ = CDAB C->D
• D+ = DABC D->C
• E+ = E (Trivial) So omitted
• CD+ =CDAB ( Trivial ) So omitted
• DE+=DEABC=> DE->C (Redundant= D->C) So omitted
• CE+=CEDAB => CE->D ( Redundant = C-D) So omitted
• F2={C->D, D->C)
• F1UF2 = {A->BC, B->CA, C->AB, C->D, D->C)
Dependency Preserving Example
• F1 U F2 = F (Verify equivalent)
• Every functional dependency of F1UF2 is a
member of F
• Every functional dependency of F is a member
of F1UF2
Dependency Preserving Example
• F= A ->B, B->C, C ->D, D ->A
• G= F1UF2 = {A->BC, B->CA, C->AB, C->D, D->C)
• A-> B, B->C,C-D is member of G
• D-> A not present directly
• So Calculate D+ in G
• D+ =DCAB ( D->A Exist)
• G Covers F
• Verify F Cover G,
– It would be definitely cover, because G derived from F.
• F Covers G, All the original dependencies are preserved.
Dependency Preserving Example

• Consider relation ABCD, with FD’s :


A ->B, B ->C, C ->D
• Decompose into two relations: ABC and CD.
All the original dependencies are preserved or
not.
Dependency Preserving Example

• Consider relation ABCD, with FD’s:


A ->B, B ->C, C->D
• Decompose into two relations: ACD and BC.
• All the original dependencies are preserved or not.
Minimal Redundancy

• In order to achieve the lack of redundancy, we


do some decomposition which is represented
by several normal forms.
Lossless Check Example

• Consider five attributes: ABCDE


• Three relations: ABC, AD, BDE
• FD’s: A ->BD, B ->E
Lossless Check Example

• Consider five attributes: ABCDE


• Three relations: ABC, AD, BDE
• FD’s: A ->BD, B ->E

A B C D E
ABC
AD
BDE
Lossless Check Example

• Consider five attributes: ABCDE


• Three relations: ABC, AD, BDE
• FD’s: A ->BD, B ->E

A B C D E
ABC a a a
AD a a
BDE a a a
Lossless Check Example

• Consider five attributes: ABCDE


• Three relations: ABC, AD, BDE
• FD’s: A ->BD, B ->E

A B C D E
ABC a1 a2 a3
AD a1 a4
BDE a2 a4 a5
Lossless Check Example

• Consider five attributes: ABCDE


• Three relations: ABC, AD, BDE
• FD’s: A ->BD, B ->E

A B C D E
ABC a1 a2 a3 b14 b15
AD a1 b22 b23 a4 b25
BDE b31 a2 b33 a4 a5
Lossless Check Example

• Consider five attributes: ABCDE


• Three relations: ABC, AD, BDE
• FD’s: A ->BD, B ->E

A B C D E
ABC a1 a2 a3 b14 b15
AD a1 b22 b23 a4 b25
BDE b31 a2 b33 a4 a5
Lossless Check Example
A B C D E

ABC a1 a2 a3 b14 b15

AD a1 b22 b23 a4 b25

BDE b31 a2 b33 a4 a5


a1 ->a2 b14 a1 ->a2 a4
Consider A ->BD a1 ->b22 a4 a1 ->a2 a4
b31 ->a2 a4 b31 ->a2 a4
A B C D E

ABC a1 a2 a3 a4 b15

AD a1 a2 b23 a4 b25

BDE b31 a2 b33 a4 a5


Lossless Check Example

A B C D E

ABC a1 a2 a3 a4 b15

AD a1 a2 b23 a4 b25

BDE b31 a2 b33 a4 a5

Consider B ->E Consider B ->E


a2 -> b15 a2 -> a5
a2 ->b25 a2 ->a5
a2 ->a5 a2 ->a5
A B C D E
Atleast one row
ABC a1 a2 a3 a4 a5 must be
completely a.
AD a1 a2 b23 a4 a5
Therefore, this
BDE b31 a2 b33 a4 a5 decomposition is
lossless

You might also like