Date post: | 03-Apr-2018 |
Category: |
Documents |
Upload: | haneesha-muddasani |
View: | 218 times |
Download: | 0 times |
of 30
7/29/2019 Lt17 Decomposition
1/30
Database Systems and
Applications
Lecture 17
Decomposition
7/29/2019 Lt17 Decomposition
2/30
What is Decomposition?
Decomposition the process of breaking downin parts or elements.
Decomposition in database means breakingtables down into multiple tables
From Database perspective means going to ahigher normal form
7/29/2019 Lt17 Decomposition
3/30
Decomposition
Important that decompositions are good,
Two Characteristics of Good Decompositions
1) Lossless
2) Preserve dependencies
7/29/2019 Lt17 Decomposition
4/30
Problems with Decomposition
Some queries become more expensive
Given instances of the decomposed relations,we may not be able to reconstruct thecorresponding instance of the original relation information loss.
7/29/2019 Lt17 Decomposition
5/30
What is lossless?
Lossless means functioning without a loss.
In other words, retain everything.
Important for databases to have this feature.
7/29/2019 Lt17 Decomposition
6/30
A decomposition is lossless if we can recover:R(A,B,C)
R1(A,B) R2(A,C)
R(A,B,C) should be the same asR(A,B,C)
Must ensure R = R
Decompose
Recover
Lossless Decomposition
7/29/2019 Lt17 Decomposition
7/30
Lossless Decomposition
Sometimes the same set of data is reproduced:
(Word, 100) + (Word, WP) (Word, 100, WP) (Oracle, 1000) + (Oracle, DB) (Oracle, 1000, DB) (Access, 100) + (Access, DB) (Access, 100, DB)
Name Price Category
Word 100 WP
Oracle 1000 DB
Access 100 DB
Name Price
Word 100
Oracle 1000
Access 100
Name Category
Word WP
Oracle DB
Access DB
7/29/2019 Lt17 Decomposition
8/30
Lossy Decomposition Sometimes its not:
(Word, WP) + (100, WP) = (Word, 100, WP) (Oracle, DB) + (1000, DB) = (Oracle, 1000, DB) (Oracle, DB) + (100, DB) = (Oracle, 100, DB) (Access, DB) + (1000, DB) = (Access, 1000, DB) (Access, DB) + (100, DB) = (Access, 100, DB)
Name Price Category
Word 100 WP
Oracle 1000 DB
Access 100 DB
Category Name
WP Word
DB Oracle
DB Access
Category Price
WP 100
DB 1000
DB 100
Whats
wrong?
7/29/2019 Lt17 Decomposition
9/30
Lossy Decomposition
Employee Project Branch
Samu Mars Warangal
Soumini Jupiter Hyderabad
Soumini Venus Hyderabad
Sekhar Saturn HyderabadSekhar Venus Hyderabad
Functional dependencies:
Employee Branch, Proje ct Branch
T
7/29/2019 Lt17 Decomposition
10/30
Lossy Decomposition
Decomposition of the previous relation
Employee Branch
Samu Warangal
Soumini Hyderabad
Sekhar Hyderabad
Project Branch
Mars Warangal
Jupiter Hyderabad
Saturn Hyderabad
Venus Hyderabad
T1 T2
7/29/2019 Lt17 Decomposition
11/30
Lossy Decomposition
After Natural Join
Employee Project Branch
Samu Mars Warangal
Soumini Jupiter Hyderabad
Soumini Venus Hyderabad
Sekhar Saturn Hyderabad
Sekhar Venus Hyderabad
Soumini Saturn Hyderabad
Sekhar Jupiter Hyderabad
Original Relation
The result is different from the original relation:the information can not be reconstructed.
Employee Project Branch
Samu Mars Warangal
Soumini Jupiter Hyderabad
Soumini Venus Hyderabad
Sekhar Saturn Hyderabad
Sekhar Venus Hyderabad
7/29/2019 Lt17 Decomposition
12/30
Lossless Decomposition Property
The decomposition of R into R1 and R2 islossless withrespect to F if and only if the closure of F containseither:
R1 R2 (R1 intersect R2) R1, that is: allattributes common to both R1 and R2 functionallydetermine ALL the attributes in R1 OR
R1 R2 (R1 intersect R2) R2, that is: allattributes common to both R1 and R2 functionallydetermine ALL the attributes in R2
7/29/2019 Lt17 Decomposition
13/30
Ensuring lossless decomposition
R(A1, ..., An, B1, ..., Bm, C1, ..., Cp)R(A1, ..., An, B1, ..., Bm, C1, ..., Cp)
If A1, ..., AnB1, ..., Bmor A1, ..., AnC1, ..., CpThen the decomposition is lossless
R1(A1, ..., An, B1, ..., Bm)R1(A1, ..., An, B1, ..., Bm) R2(A1, ..., An, C1, ..., Cp)
R2(A1, ..., An, C1, ..., Cp)
Note: dont need both
7/29/2019 Lt17 Decomposition
14/30
In Simpler Terms
R1 R2 R1
R1 R2 R2
If R is split into R1 and R2, for the decomposition to belossless then at leastone of the two should hold true.
Projecting on R1 and R2, and joining back, results in the
relation you started with
7/29/2019 Lt17 Decomposition
15/30
Why lossless?
Ensures that attributes involved in the natural join(R1 R2) are a candidate key for at least one ofthe two relations.
This ensures we can never get the situation wherefalse tuples are generated, as for any value on thejoin attributes there will be a unique tuple in one
of the relations.
7/29/2019 Lt17 Decomposition
16/30
Example of Lossless Decomposition
GIVEN:LENDINGSCHEME=(BRANCHNAME, ASSETS, BRANCHCITY,LOANNUMBER, CUSTOMERNAME, AMOUNT)
FD'S:
BRANCHNAME ASSETS BRANCHCITYLOANNUMBER AMOUNT BRANCHNAME
DECOMPOSE LENDINGSCHEME INTO:
1. BRANCHSCHEME=(BRANCHNAME, ASSETS, BRANCHCITY)
2. BORROWSCHEME=(BRANCHNAME, LOANNUMBER,CUSTOMERNAME, AMOUNT)
7/29/2019 Lt17 Decomposition
17/30
Example of Lossless Decomposition
SHOW THAT THE DECOMPOSITION IS A LOSSLESSDECOMPOSITION
USE AUGMENTATION RULE ON FIRST FD TO OBTAIN:BRANCHNAME BRANCHNAME ASSETSBRANCHCITY
INTERSECTION OF BRANCHSCHEME ANDBORROWSCHEME IS BRANCHNAME
BRANCHNAME BRANCHSCHEMESO, INITIAL DECOMPOSITION IS A LOSSLESS
7/29/2019 Lt17 Decomposition
18/30
Example 2
GIVEN:BORROWSCHEME=(BRANCHNAME, LOANNUMBER,
CUSTOMERNAME, AMOUNT)FD'S:
LOANNUMBER AMOUNT BRANCHNAME
DECOMPOSE BORROWSCHEME INTO:
1. LOAN-INFO-SCHEME=(BRANCHNAME, LOANNUMBER,AMOUNT)
2. CUSTOMER-LOAN-SCHEME=(LOANNUMBER,CUSTOMERNAME)
7/29/2019 Lt17 Decomposition
19/30
Example 2 (cont)
SHOW THAT THE DECOMPOSITION IS A LOSSLESSDECOMPOSITION
1. USE AUGMENTATION RULE ON FD TO OBTAIN:LOANNUMBER LOANNUMBER AMOUNT
BRANCHNAME
1. INTERSECTION OF LOAN-INFO-SCHEME AND CUSTOMER-LOAN-SCHEME IS LOANNUMBER
1. LOANNUMBER LOAN-INFO-SCHEME1. SO, INITIAL DECOMPOSITION IS A LOSSLESS
7/29/2019 Lt17 Decomposition
20/30
7/29/2019 Lt17 Decomposition
21/30
Example
R1 (A1, A2, A3, A5)
R2 (A1, A3, A4)
R3 (A4, A5)
FD1: A1 A3 A5
FD2: A5 A1 A4
FD3: A3 A4 A2
7/29/2019 Lt17 Decomposition
22/30
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 (cont)
7/29/2019 Lt17 Decomposition
23/30
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 (cont)
7/29/2019 Lt17 Decomposition
24/30
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 (cont)
7/29/2019 Lt17 Decomposition
25/30
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 (cont)
7/29/2019 Lt17 Decomposition
26/30
By 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)
Example (cont)
7/29/2019 Lt17 Decomposition
27/30
Example 1
R(A B C D E)
FD1 = (A B)
FD2 = (BC E)
FD3 = (ED
A)R1=(AB);
R2=(ACDE);
7/29/2019 Lt17 Decomposition
28/30
Example 2
Is this decomposition lossless?
R (A B C D E)
FD1 AB CFD2 C E
FD3 BD
FD4 EA
R1=(BCD);
R2=(ACE);
7/29/2019 Lt17 Decomposition
29/30
Example 3
R(A B C D E)
FD1: A BC
FD2: BD CE
FD3: E AD
FD4: CE A
R1(ABC) =
R2 (BCDE) =
7/29/2019 Lt17 Decomposition
30/30
Conclusion
Decomposing is the act of breaking tablesdown in order to achieve higher normal form.
Decompositions should always be lossless.This confirms that information in the originalrelation can be accurately reconstructedbased on the decomposed relations.
Remember that for a decomposition to beconsidered GOOD it must also preservefunctional dependencies.