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 ProjName Location Budget P1 Training Geneva 98000 P2 Advertising Geneva 72000 P3 Management Munich 150000 P4 Customer Support Zurich 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 1
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. A1 Q1 0 1 1 0 Q2 1 1 1 0 Q3 1 0 0 1 Q4 0 0 1 0 Figure1: This matrix shows which attributes each query uses. S1 S2 S3 Q1 10 20 0 Q2 5 0 10 Q3 0 35 5 Q4 0 10 0 Figure 2: This matrix shows how often each site executes queries. 2
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) don t 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 Salary E1 Federer 20000 E2 Klum 10000 E3 Spears 12000 E4 Montoya 6000 E5 Beckham 15000 E6 Lopez 18000 3
Projects, P.F1, P.F2 ProjNo ProjName Location Budget P1 Training Geneva 98000 P2 Advertising Geneva 72000 P3 Management Munich 150000 P4 Customer Support Zurich 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 b) PA.P.F1, PA.P.F2 EmpNo ProjNo MonthsSpent EmpNo ProjNo MonthsSpent E1 P1 3 S1 E1 P1 3 E2 P2 4 S2 E2 P2 4 E2 P4 2 S3 E2 P4 2 E3 P3 8 S4 E3 P3 8 E4 P1 6 S5 E4 P1 6 E5 P2 9 S6 E5 P2 9 E6 P4 4.5 S7 E6 P4 4.5 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. 4
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. A1 Q1 0 1 1 0 Q2 1 1 1 0 Q3 1 0 0 1 Q4 0 0 1 0 S1 S2 S3 Sum Q1 10 20 0 30 Q2 5 0 10 15 Q3 0 35 5 40 Q4 0 10 0 10 Bond energy algorithm: A1 is the primary key and has to be in all fragments. Therefore, we don t have to consider it. We can calculate the following attribute affinity matrix: 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 Q1 1 1 0 Q2 1 1 0 Q3 0 0 1 Q4 0 1 0 S1 S2 S3 Sum Q1 10 20 0 30 Q2 5 0 10 15 Q3 0 35 5 40 Q4 0 10 0 10 5
accesses(fragment 1: {A2}): 0 accesses(fragment 2: {A3, A4}): 50 accesses(fragment 1 AND fragment 2): 45 sq = -1975 accesses(fragment 1: {A2, A3}): 55 accesses(fragment 2: {A4}): 40 accesses(fragment 1 AND fragment 2): 0 sq = 2200 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}. 6
The same calculation with all attributes: We can calculate the following attribute affinity matrix: A1 A1 55 15 15 40 A2 15 45 45 0 A3 15 45 55 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
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 A1 A3 A2 A4 40 40 0 0 A1 40 55 15 15 A3 0 15 55 45 A2 0 15 45 45 A1 Q1 0 1 1 0 Q2 1 1 1 0 Q3 1 0 0 1 Q4 0 0 1 0 S1 S2 S3 Sum Q1 10 20 0 30 Q2 5 0 10 15 Q3 0 35 5 40 Q4 0 10 0 10 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 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): 40 accesses(fragment 2): 40 accesses(fragment 1 AND fragment 2): 15 sq = 1375 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): 50 accesses(fragment 2): 0 8
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. 9