1. Lect 9 Decomposition
1. Lect 9 Decomposition
DECOMPOSITION
TO HIGHER
NORMAL FORMS
CARTESIAN (OR CROSS)
PRODUCT OPERATION
This operation is used to combine tuples from two
relations in a combinatorial fashion.
In general, the result of R(A1, A2, . . ., An) X S(B1, B2, . .
., Bm) is a relation Q with degree n + m attributes
Q(A1, A2, . . ., An, B1, B2, . . ., Bm), in that order.
The resulting relation Q has one tuple for each
combination of tuples—one from R and one from S.
Hence, if R has nR tuples (denoted as |R| = nR ),
R <join condition> S
where R and S can be any relations that result from general relational
JOIN OPERATION EXAMPLE
Relation R A B C Relation S C D
2 4 3 3 4
A B C C D 3 4 2 2 4
2 4 3 3 4 4 4 3 3 3
2 4 3 2 4 5 3 3
2 4 3 3 3
3 4 2 3 4 A B C C D A B C D
3 4 2 2 4 2 4 3 3 4 2 4 3 4
3 4 2 3 3 2 4 3 3 3 2 4 3 3
4 4 3 3 4 3 4 2 2 4 3 4 2 4
4 4 3 2 4 4 4 3 3 4 4 4 3 4
4 4 3 3 3 4 4 3 3 3 4 4 3 3
5 3 3 3 4 5 3 3 3 4 5 3 3 4
5 3 3 2 4 5 3 3 3 3 5 3 3 3
5 3 3 3 3
Step 2: σ R.C = S.C ( R X S)
Step 1: Cross Product R X S Step 3: π (σ R.C = S.C ( R X S))
LOSSLESS (NON-ADDITIVE) JOIN PROPERTY
OF RELATIONAL DECOMPOSITION
{ R1 ⋈ R2 ⋈ …. ⋈ Rn } ⊇ R
If { R1 ⋈ R2 ⋈ …. ⋈ Rn } = R ⇒ Lossless Join
Decomposition
If { R1 ⋈ R2 ⋈ …. ⋈ Rn } ⊃ R ⇒ Lossy Join
Decomposition
LOSSLESS JOIN PROPERTY (CONT.)
Relation R Data
Relation R1 Relation R2
with Data with Data
LOSSLESS JOIN DECOMPOSTION
EXAMPLE
EmpInfo
Emp_ID Emp_Name Emp_Age Emp_Loc Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E002 Henry 32 Alabama Dpt2 HR
E003 Tom 22 Texas Dpt3 Finance
EmpDetails DeptDetails
Emp_ID Emp_Name Emp_Age Emp_Loc Dept_ID Emp_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 E001 Operations
E002 Henry 32 Alabama Dpt2 E002 HR
E003 Tom 22 Texas Dpt3 E003 Finance
Join Result
Emp_ID Emp_Name Emp_Age Emp_Loc Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E002 Henry 32 Alabama Dpt2 HR
E003 Tom 22 Texas Dpt3 Finance
LOSSY JOIN DECOMPOSTION EXAMPLE
EmpInfo
Emp_ID Emp_Name Emp_Age Emp_Loc Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E001 Jacob 29 Alabama Dpt2 HR
E002 Tom 32 Alabama Dpt1 Operations
E003 Tom 22 Texas Dpt2 HR
EmpDetails DeptDetails
Emp_ID Emp_Name Emp_Age Emp_Loc Dept_ID Dept_Name Emp_Name
E001 Jacob 29 Alabama Dpt1 Operations Jacob
E002 Tom 32 Alabama Dpt2 HR Jacob
E003 Tom 22 Texas Dpt1 Operations Tom
Dpt2 HR Tom
Join Result
Emp_ID Emp_Name Emp_Age Emp_Loc Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E001 Jacob 29 Alabama Dpt2 HR
E002 Tom 32 Alabama Dpt1 Operations
E003 Tom 22 Texas Dpt2 HR
E002 Tom 32 Alabama Dpt2 HR
E003 Tom 22 Texas Dpt1 Operations
HOW TO CHECK A
DECOMPOSITION IS LOSSLESS OR
LOSSY?
Let R be the relational schema decomposed into R1,
R2,…Rn and R1 ∩ R2 = X attribute
Case 1: If X is superkey for atleast one relation
R1 or R2, the decomposition is lossless.
Case 2: If If X is not superkey for
atleast one relation R1 or R2,
the decomposition is lossy.
Case 3: If R1 ∩ R2 = Ø,
the decomposition is lossy.
LOSSLESS/LOSSY DECOMPOSITION
EXAMPLE
Solution:
R1 ( A , B ) ∩ R 2 ( C , D ) = Φ
1. R(A,B,C,D)
F = {A → B, B → C, C → D, D → B }
D = ( AB, BC, BD )
2. R (A, B, C, D, E)
F = { AB C, C D, B E }
D = ( ABC, CD)
3. R (A, B, C, D, E)
F = { AB C, C D, B E }
D = ( ABC, CDE )
4. R (A, B, C, D, E)
F = { AB C, C D, B E }
D = ( ABC, ABDE)
SOLUTION PRACTICE DRILL
1. F = { A → B, B → C, C → D, D → B }
R1 ( A , B ) , R2 ( B , C ) and R3 ( B , D )
Case 1 Case 2
R1 ∩ R2 = B
R2 ∩ R3 = B
B+ = B, C for R2 (B, C) ∴ B is
B+ = B, C for R2 (B, C) ∴ B is
superkey in R2
superkey in R2
R12 (A, B, C) ∩ R3 = B
R1 ∩ R23 (B, C, D) = B
B+ = B, C for R12 (A, B, C)
B+ = B, C, D ∴ B is superkey in
B+ = B for R3 (B, D) ∴ B is not
R23
superkey for any sub-relation
2. F = { AB C, C D, B E } D = ( ABC, CD)
C+ = C, D ∴ C is superkey in relation CD
3. F = { AB C, C D, B E } D = ( ABC, CDE )
C+= C, D
4. F = { AB C, C D, B E }
D = ( ABC, ABDE)
D A}.
Solution:
Attribute closure:
AA BB C ACD D AD
R1(CD), R2(AC) and R3(BC) but R1(AD), R2(CD) and R3(BC) but
D A and AB C are not AB C is not preserved
preserved
DECOMPOSITION TO HIGHER
NORMAL FORM DRILL
1. Relation R ( ABCDE )
F = { AB C, C D, B E }
2. Relation R ( ABCDEFGHIJ )
F ={ AB C, C D, A E, E FG, B H, H IJ }
3. Relation R ( ABC )
F = { AB C, C A }
SOLUTION - DECOMPOSITION TO
HIGHER NORMAL FORM DRILL
1. Relation R (ABCDE)
F = { AB C, C D, B E }
AB+ = A, B, C, D, E
A+ = A
B+ = B, E FD AB C CD BE
BCNF ✔ X X
3NF ✔ X X
2NF ✔ ✔ X
1NF ✔ ✔ ✔
R (ABCDE)
ABCD BE
AB C
BE
CD
R (ABCDE)
ABCD
ABC
AB C
CD
CD
BE
BE
2. Relation R ( ABCDEFGHIJ )
F ={ AB C, C D, A E, E FG, B H, H IJ }
AB+ = A, B, C, D, E, F, G, H, I, J
R (ABCDEFGHIJ)
AB C AE BH
CD E FG H IJ
R (ABCDEFGHIJ)
CD EFG HIJ
CD E FG H IJ
Case1: If R1 ( BC ) and R2 ( AC )
✔ (over FDs)
Achieve 0%
X X X X (over
Redundancy
MVDs)
LLJ Satisfied ✔ ✔ ✔ ✔
DP Satisfied ✔ ✔ ✔ X
Best
Bestaccurate
accurateform
formisis3NF
3NFbecause
becausedependency
dependency
preservation
preservationand
andlossless
losslessjoin
joinproperties
propertiesare
are
more
moreimportant
important
MULTI-VALUED DEPENDENCY
(MVD)
A multi-valued dependency (MVD) X Y specified
on relation schema R, where X and Y are both subsets
of R, specifies the following constraint:
Student
StudentName CourseDiscipline Activities
StudentName CourseDiscipline
StudentName Activities
MVD RULES
Complementation: If X Y, and Z is all the other
attributes i.e. Z = (R - (X υ Y), then X Z.
Eg. R(ABCD) if A B then, A CD
and
Non-trivial
Non-trivial FD
MVD
XY and X Y
X: superkey
X: superkey
FOURTH NORMAL FORM EXAMPLE
Relation Drinkers(name, addr, phones, beersLiked)
FD: name addr
MVD’s: name phones
name beersLiked
Key is { name, phones, beersLiked }
Drinkers
(name, addr,Drinkers1
phones, beersLiked)
(name, addr)
name addr
Drinkers2
(name, phones, beersLiked)
Drinkers3
(name, phones)
name phones
Drinkers4
(name, beersLiked)
name beersLiked
FIFTH (PROJECT - JOIN)
NORMAL FORM (PJNF)
a) It is in 4NF
and
PROS