You are on page 1of 9

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

WS 2004/2005

Distributed Information Systems - Exercise 4


Schema Fragmentation
Date: 23.11.2004 Return: 30.11.2004

1. Horizontal Fragmentation
Given the following relational database: Employees EmpNo EmpName Salary E1 Federer 20000 E2 Klum 10000 E3 Spears 12000 E4 Montoya 6000 E5 Beckham 15000 E6 Lopez 18000 ProjectAssignments EmpNo ProjNo MonthsSpent E1 P1 3 E2 P2 4 E2 P4 2 E3 P3 8 E4 P1 6 E5 P2 9 E6 P4 4.5

Projects ProjNo P1 P2 P3 P4

ProjName Training Advertising Management Customer Support

Location Geneva Geneva Munich Zurich

Budget 98000 72000 150000 120000

Typical queries from applications are: At the controlling department located in Geneva: A1 SELECT P.ProjNo, P.Budget, PA.EmpNo, PA.MonthsSpent FROM Projects P, ProjectAssignments PA WHERE P.ProjNo = PA.ProjNo AND P.Budget < 110000 A2 SELECT PA.EmpNo, PA.ProjNo, PA.MonthsSpent FROM Employees E, ProjectAssignments PA WHERE E.EmpNo = PA.EmpNo AND E.Salary > 11500

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

At the human resource department located in Munich: A3 SELECT * FROM Employees E A4 SELECT E.*, PA.MonthsSpent FROM Employees E, ProjectAssignments PA WHERE E.EmpNo = PA.EmpNo

At the sales coordination department located in Zurich: A5 SELECT * FROM Projects WHERE Location != Geneva a) For the relations Employees and Projects, determine minimal sets of simple predicates using the MinFrag algorithm. b) What are the corresponding fragments of the two relations Employees and Projects? c) How would you fragment ProjectAssignments horizontally? Give a short discussion of your decision.

2. Vertical Fragmentation
Let Q = {Q1, Q2, Q3, Q4} be a set of queries, A = {A1, A2, A3, A4} a set of attributes, and S = {S1, S2, S3} a set of sites. The matrix in the Figure 1 describes the attribute usage values and the one in Figure 2 gives the application access frequencies. Assume that A1 is the primary key. Use the bond energy algorithm and the vertical partitioning algorithm to obtain a vertical fragmentation of the set of attributes in A.

Q1 Q2 Q3 Q4

A1 0 1 1 0

A2 1 1 0 0

A3 1 1 0 1

A4 0 0 1 0

Figure1: This matrix shows which attributes each query uses.

Q1 Q2 Q3 Q4

S1 10 5 0 0

S2 20 0 35 10

S3 0 10 5 0

Figure 2: This matrix shows how often each site executes queries. 2

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

WS 2004/2005

Distributed Information Systems - Exercise 4 - Solution


Schema Fragmentation

1. Horizontal Fragmentation
d) For the relations Employees and Projects, determine minimal sets of simple predicates using the MinFrag algorithm. For the table Projects the following simple predicates appear in the application queries: p1 = (Budget < 110000) p2 = (Location != Geneva) Using the MinFrag algorithm we get: Step 1: add p1 = (Budget < 110000) Step 2: add p2 = (Location != Geneva) fragments

ok, p1 added not added as (p1 AND p2) and (p1 AND p2) dont create any new

{Budget < 110000} is the minimal complete set of predicates. For the table Employees there is only a single simple predicate. The minimal complete set contains therefore only one predicate: {Salary > 11500}

e) What are the corresponding fragments of the two relations Employees and Projects? Employees, E.F1, E.F2 EmpNo EmpName E1 Federer E2 Klum E3 Spears E4 Montoya E5 Beckham E6 Lopez

Salary 20000 10000 12000 6000 15000 18000

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

Projects, P.F1, P.F2 ProjNo ProjName P1 Training P2 Advertising P3 Management P4 Customer Support

Location Geneva Geneva Munich Zurich

Budget 98000 72000 150000 120000

f) How would you fragment ProjectAssignments horizontally? Give a short discussion of your decision.

There are two possibilities to fragment ProjectAssignments horizontally: a) by deriving from Employees and b) by deriving from Projects. a) PA.E.F1, PA.E.F2 EmpNo ProjNo MonthsSpent E1 P1 3 E2 P2 4 E2 P4 2 E3 P3 8 E4 P1 6 E5 P2 9 E6 P4 4.5 b) PA.P.F1, PA.P.F2 EmpNo ProjNo MonthsSpent E1 P1 3 E2 P2 4 E2 P4 2 E3 P3 8 E4 P1 6 E5 P2 9 E6 P4 4.5

S1 S2 S3 S4 S5 S6 S7

Applications A1 & A2 in Geneva access S1, S2, S4, S5, S6, and S7. Application A4 in Munich accesses S1 to S7. Conclusion: All four fragments (PA.E.F1, PA.E.F2, PA.P.F1, and PA.P.F2) are accessed from Geneva and Munich. Therefore, we would not fragment ProjectAssignments and store it either in Geneva or Munich depending on the access frequencies of the applications.

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

2. Vertical Fragmentation
Use the bond energy algorithm and the vertical partitioning algorithm to obtain a vertical fragmentation of the set of attributes in A. S1 10 5 0 0 S2 20 0 35 10 S3 0 10 5 0 Sum 30 15 40 10

Q1 Q2 Q3 Q4

A1 0 1 1 0

A2 1 1 0 0

A3 1 1 0 1

A4 0 0 1 0

Q1 Q2 Q3 Q4

Bond energy algorithm:


A1 is the primary key and has to be in all fragments. Therefore, we dont have to consider it. We can calculate the following attribute affinity matrix: A2 A2 45 A3 45 40 0 A3 45 55 0 A4 0 0 40

bond(A2, A3) = 45*45 + 45*55 + 0*0 = 4500 bond(A2, A4) = 45*0 + 45*0 + 0*40 = 0 bond(A3, A4) = 45*0 + 55*0 + 0*40 = 0 Calculate the contribution of the column depending on its position: A4-A2-A3 cont(_, A4, A2) = bond(_, A4) + bond (A4, A2) - bond(_, A2) = 0 A2-A4-A3 cont(A2, A4, A3) = bond(A2, A4) + bond(A4, A3) - bond(A2, A3) = 0 + 0 - 4500 = -4500 A2-A3-A4 cont(A3, A4, _) = bond(A3, A4) + bond(A4, _) - bond(A3, _) = 0 Both A4-A2-A3 and A2-A3-A4 look good

A2 A2 45 A3 45 40 0

A3 45 55 0

A4 0 0 40

Q1 Q2 Q3 Q4

A2 1 1 0 0

A3 1 1 0 1

A4 0 0 1 0

Q1 Q2 Q3 Q4 5

S1 10 5 0 0

S2 20 0 35 10

S3 0 10 5 0

Sum 30 15 40 10

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

A2 A3 A4 A2 45 45 0 A3 45 55 0 40 0 0 40 accesses(fragment 1: {A2}): 0 accesses(fragment 2: {A3, A4}): 50 accesses(fragment 1 AND fragment 2): 45 sq = -1975 A2 A3 A4 A2 45 45 0 A3 45 55 0 40 0 0 40 accesses(fragment 1: {A2, A3}): 55 accesses(fragment 2: {A4}): 40 accesses(fragment 1 AND fragment 2): 0 sq = 2200 A2 A2 45 A3 45 40 0 A3 45 55 0 A4 0 0 40

accesses(fragment 1: {A2, A4}): 40 accesses(fragment 2: {A3}): 10 accesses(fragment 1 AND fragment 2): 45 sq = -1625 The two partitions are therefore {A1, A4} and {A1, A2, A3}.

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

The same calculation with all attributes:

We can calculate the following attribute affinity matrix: A1 A1 55 A2 15 A3 15 40 40 A2 15 45 45 0 A3 15 45 55 0 A4 40 0 0 40

We can randomly choose the first two columns. We choose A1, A2. Two determine the position of A3 first calculate the bond energy between two columns: bond(A1, A2) = 55*15 + 15*45 + 15*45 + 40*0 = 2175 bond(A2, A3) = 15*15 + 45*45 + 45*55 + 0*0 = 4725 bond(A1, A3) = 55*15 + 15*45 + 15*55 + 40 *0 = 2325

Calculate the contribution of the column depending on its position: A3-A1-A2: cont(_, A3, A1) = bond(_, A3) + bond(A3, A1) - bond(_, A1) = 0 + 2325 0 = 2325 A1-A3-A2: cont(A1, A3, A2) = bond(A1, A3) + bond(A3, A2) - bond(A1, A2) = 2325 + 4725 2175 = 4875 A1-A2-A3: cont(A2, A3, A_) = bond(A2, A3) + bond(A3, A_) - bond(A2, A_) = 4725 + 0 0 = 4725

The order A1-A3-A2 leads to the highest bond energy.

Same for A4: bond(A1, A4) = 55*40 + 15*0 + 15*0 + 40*40 = 3800 bond(A2, A4) = 15*40 + 45*0 + 45*0 + 0*40 = 600 bond(A3, A4) = 15*40 + 45*0 + 55*0 + 0*40 = 600 A4-A1-A3-A2: cont(_, A4, A1) = bond(_, A4) + bond(A4, A1) bond(_, A1) = 0 + 3800 0 = 3800 A1-A4-A3-A2: cont(A1, A4, A3) = bond(A1, A4) + bond(A4, A3) bond (A1, A3) = 3800 + 600 2325 = 2075 A1-A3-A4-A2: cont(A3, A4, A2) = bond(A3, A4) + bond(A4, A2) bond(A3, A2) = 600 + 600 4725 = -3525 7

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

A1-A3-A2-A4: cont(A2, A4, A_) = bond(A2, A4) + bond(A4, A_) bond(A2, A_) = 600 + 0 0 = 600 A4-A1-A3-A2 looks good A4 40 40 0 0 A1 40 55 15 15 A3 0 15 55 45 A2 0 15 45 45 A1 0 1 1 0 A2 1 1 0 0 A3 1 1 0 1 A4 0 0 1 0 S1 10 5 0 0 S2 20 0 35 10 S3 0 10 5 0 Sum 30 15 40 10

A4 A1 A3 A2

Q1 Q2 Q3 Q4

Q1 Q2 Q3 Q4

There are now several possibilities to split the table: split quality (sq) = accesses(fragment 1) * accesses(fragment 2) - accesses(fragment 1 AND fragment 2)^2

A4 A1 A3 A2 A4 40 40 0 0 A1 40 55 15 15 A3 0 15 55 45 A2 0 15 45 45 accesses(fragment 1): 0 accesses(fragment 2): 55 accesses(fragment 1 AND fragment 2): 40 sq = -1600 A4 40 40 0 0 A1 40 55 15 15 A3 0 15 55 45 A2 0 15 45 45

A4 A1 A3 A2

accesses(fragment 1): 40 accesses(fragment 2): 40 accesses(fragment 1 AND fragment 2): 15 sq = 1375 A4 40 40 0 0 A1 40 55 15 15 A3 0 15 55 45 A2 0 15 45 45

A4 A1 A3 A2

accesses(fragment 1): 50 accesses(fragment 2): 0 8

2005, EPFL-IC, Laboratoire de Systmes d'Information Rpartis (LSIR) Distributed Information Systems - Exercise 4 Schema Fragmentation

accesses(fragment 1 AND fragment 2): 45 sq = -2025

The two partitions are therefore {A1, A4} and {A1, A2, A3}. The primary key A1 has to be in all partitions.

You might also like