Download presentation
Presentation is loading. Please wait.
Published bySteven Martin Modified over 9 years ago
1
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/1 Οι διαφάνειες καλύπτουν μέρος των Κεφαλαίων 7&8: Distributed Database QueryProcessing and Optimization του βιβλίου των M.T. Özsu, P. Valduriez: Principles of Distributed Database Systems (3 rd Ed)
2
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/2 Outline Introduction Background Distributed Database Design Database Integration Semantic Data Control Distributed Query Processing ➡ Overview ➡ Query decomposition and localization ➡ Distributed query optimization Multidatabase query processing Distributed Transaction Management Data Replication Parallel Database Systems Distributed Object DBMS Peer-to-Peer Data Management Web Data Management Current Issues
3
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/3 Step 1 – Query Decomposition Input : Calculus query on global relations Normalization ➡ manipulate query quantifiers and qualification Analysis ➡ detect and reject “incorrect” queries ➡ possible for only a subset of relational calculus Simplification ➡ eliminate redundant predicates Restructuring ➡ calculus query algebraic query ➡ more than one translation is possible ➡ use transformation rules
4
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/4 Normalization Lexical and syntactic analysis ➡ check validity (similar to compilers) ➡ check for attributes and relations ➡ type checking on the qualification Put into normal form ➡ Conjunctive normal form ( p 11 p 12 … p 1 n ) … ( p m 1 p m 2 … p mn ) ➡ Disjunctive normal form ( p 11 p 12 … p 1 n ) … ( p m 1 p m 2 … p mn ) ➡ OR's mapped into union ➡ AND's mapped into join or selection
5
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/5 Analysis Refute incorrect queries Type incorrect ➡ If any of its attribute or relation names are not defined in the global schema ➡ If operations are applied to attributes of the wrong type Semantically incorrect ➡ Components do not contribute in any way to the generation of the result ➡ Only a subset of relational calculus queries can be tested for correctness ➡ Those that do not contain disjunction and negation ➡ To detect ✦ connection graph (query graph) ✦ join graph
6
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/6 Analysis – Example SELECTENAME,RESP FROMEMP, ASG, PROJ WHEREEMP.ENO = ASG.ENO AND ASG.PNO = PROJ.PNO ANDPNAME = "CAD/CAM" ANDDUR ≥ 36 ANDTITLE = "Programmer" Query graph Join graph DUR≥36 PNAME=“CAD/CAM” ENAME EMP.ENO=ASG.ENO ASG.PNO=PROJ.PNO RESULT TITLE = “Programmer” RESP ASG.PNO=PROJ.PNO EMP.ENO=ASG.ENO ASGPROJEMP PROJASG
7
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/7 Analysis If the query graph is not connected, the query may be wrong or use Cartesian product SELECTENAME,RESP FROMEMP, ASG, PROJ WHEREEMP.ENO = ASG.ENO ANDPNAME = "CAD/CAM“ PNAME=“CAD/CAM” ENAME RESULT RESP ASGPROJEMP
8
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/8 Simplification Why simplify? ➡ Remember the example How? Use transformation rules ➡ Elimination of redundancy ✦ idempotency rules p 1 ¬( p 1 ) false p 1 ( p 1 ∨ p 2 ) p 1 p 1 false false … ➡ Application of transitivity ➡ Use of integrity rules
9
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/9 Simplification – Example SELECTTITLE FROMEMP WHEREEMP.ENAME = "J. Doe" OR(NOT(EMP.TITLE = "Programmer") AND(EMP.TITLE = "Programmer" OREMP.TITLE = "Elect. Eng.") ANDNOT(EMP.TITLE = "Elect. Eng.")) SELECTTITLE FROMEMP WHEREEMP.ENAME = "J. Doe"
10
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/10 Restructuring Convert relational calculus to relational algebra Make use of query trees Example Find the names of employees other than J. Doe who worked on the CAD/CAM project for either 1 or 2 years. SELECTENAME FROMEMP, ASG, PROJ WHEREEMP.ENO = ASG.ENO ANDASG.PNO = PROJ.PNO ANDENAME≠ "J. Doe" ANDPNAME = "CAD/CAM" AND(DUR = 12 OR DUR = 24) ENAME σ DUR=12 OR DUR=24 σ PNAME=“CAD/CAM” σ ENAME≠“J. DOE” PROJASGEMP Project Select Join ⋈ PNO ⋈ ENO
11
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/11 Restructuring –Transformation Rules Commutativity of binary operations ➡ R × S S × R ➡ R ⋈ S S ⋈ R ➡ R S S R Associativity of binary operations ➡ ( R × S ) × T R × ( S × T ) ➡ ( R ⋈ S ) ⋈ T R ⋈ ( S ⋈ T ) Idempotence of unary operations ➡ A ’ ( A’ ’ ( R )) A ’ ( R ) ➡ p 1 ( A 1 ) ( p 2 ( A 2 ) ( R )) p 1 ( A 1 ) p 2 ( A 2 ) ( R ) where R [ A ] and A' A, A" A and A' A" Commuting selection with projection
12
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/12 Restructuring – Transformation Rules Commuting selection with binary operations ➡ p ( A ) ( R × S ) ( p ( A ) ( R )) × S ➡ p ( A i ) ( R ⋈ ( A j,B k ) S ) ( p ( A i ) ( R )) ⋈ ( A j,B k ) S ➡ p ( A i ) ( R T ) p ( A i ) ( R ) p ( A i ) ( T ) where A i belongs to R and T Commuting projection with binary operations ➡ C ( R × S ) A ’ ( R(A) ) × B ’ ( S(B) ) ➡ C ( R ⋈ ( A j,B k ) S ) A ’ ( R ) ⋈ ( A j,B k ) B ’ ( S ) (A’ includes Aj) ➡ C ( R S ) C ( R ) C ( S ) where R [ A ] and S [ B ]; C = A ' B ' where A' A, B' B
13
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/13 Example Recall the previous example: Find the names of employees other than J. Doe who worked on the CAD/CAM project for either one or two years. SELECT ENAME FROMPROJ, ASG, EMP WHEREASG.ENO=EMP.ENO ANDASG.PNO=PROJ.PNO ANDENAME ≠ "J. Doe" ANDPROJ.PNAME="CAD/CAM" AND(DUR=12 OR DUR=24) ENAME DUR=12 DUR=24 PNAME=“CAD/CAM” ENAME≠“J. DOE” PROJASGEMP Project Select Join ⋈ PNO ⋈ ENO
14
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/14 Equivalent Query ENAME PNAME=“CAD/CAM” (DUR=12 DUR=24) ENAME≠“J. Doe” × PROJ ASG EMP ⋈ PNO,ENO
15
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/15 EMP ENAME ENAME ≠ "J. Doe" ASGPROJ PNO,ENAME PNAME = "CAD/CAM" PNO DUR =12 DUR=24 PNO,ENO PNO,ENAME Restructuring ⋈ PNO ⋈ ENO
16
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/16 Step 2 – Data Localization Input: Algebraic query on distributed relations Determine which fragments are involved Localization program ➡ substitute for each global query its materialization program ➡ optimize
17
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/17 Example Assume ➡ EMP is fragmented into EMP 1, EMP 2, EMP 3 as follows: ✦ EMP 1 = ENO≤“E3” (EMP) ✦ EMP 2 = “E3”<ENO≤“E6” (EMP) ✦ EMP 3 = ENO≥“E6 ” (EMP) ➡ ASG fragmented into ASG 1 and ASG 2 as follows: ✦ ASG 1 = ENO≤“E3” (ASG) ✦ ASG 2 = ENO>“E3” (ASG) Replace EMP by (EMP 1 EMP 2 EMP 3 ) and ASG by (ASG 1 ASG 2 ) in any query ENAME DUR=12 DUR=24 PNAME=“CAD/CAM” ENAME≠“J. DOE” PROJ EMP 1 EMP 2 EMP 3 ASG 1 ASG 2 ⋈ PNO ⋈ ENO
18
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/18 Provides Parallellism EMP 3 ASG 1 EMP 2 ASG 2 EMP 1 ASG 1 EMP 3 ASG 2 ⋈ ENO 6 joins in total
19
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/19 Eliminates Unnecessary Work EMP 2 ASG 2 EMP 1 ASG 1 EMP 3 ASG 2 ⋈ ENO
20
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/20 Reduction for PHF Reduction with selection ➡ Relation R and F R ={ R 1, R 2, …, R w } where R j = p j ( R ) p i ( R j )= if x in R : ¬( p i ( x ) p j ( x )) ➡ Example SELECT* FROMEMP WHEREENO="E5" ENO=“E5” EMP 1 EMP 2 EMP 3 EMP 2 ENO=“E5”
21
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/21 Reduction for PHF Reduction with join ➡ Possible if fragmentation is done on join attribute ➡ Distribute join over union ( R 1 R 2 ) ⋈ S ( R 1 ⋈ S ) ( R 2 ⋈ S ) ➡ Given R i = p i ( R ) and R j = p j ( R ) R i ⋈ R j = if x in R i, y in R j : ¬( p i ( x ) p j ( y ))
22
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/22 Reduction for PHF Assume EMP is fragmented as before and ➡ ASG 1 : ENO ≤ "E3" (ASG) ➡ ASG 2 : ENO > "E3" (ASG) Consider the query SELECT* FROMEMP,ASG WHEREEMP.ENO=ASG.ENO Distribute join over unions Apply the reduction rule EMP 1 EMP 2 EMP 3 ASG 1 ASG 2 ⋈ ENO EMP 1 ASG 1 EMP 2 ASG 2 EMP 3 ASG 2 ⋈ ENO
23
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/23 Reduction for VF Find useless (not empty) intermediate relations Relation R defined over attributes A = { A 1,..., A n } vertically fragmented as R i = A ' ( R ) where A ' A : D,K ( R i ) is useless if the set of projection attributes D is not in A ' Example: EMP 1 = ENO,ENAME (EMP); EMP 2 = ENO,TITLE (EMP) SELECTENAME FROMEMP EMP 1 EMP 2 ENAME ⋈ ENO ENAME
24
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/24 Reduction for DHF Rule : ➡ Distribute joins over unions ➡ Apply the join reduction for horizontal fragmentation Example ASG 1 : ASG ⋉ ENO EMP 1 ASG 2 : ASG ⋉ ENO EMP 2 EMP 1 : TITLE=“Programmer” (EMP) EMP 2 : TITLE !=“Programmer” (EMP) Query SELECT * FROMEMP, ASG WHEREASG.ENO = EMP.ENO ANDEMP.TITLE = "Mech. Eng."
25
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/25 Generic query Selections first Reduction for DHF ASG 1 TITLE=“Mech. Eng.” ASG 2 EMP 1 EMP 2 ASG 1 ASG 2 EMP 2 TITLE=“Mech. Eng.” ⋈ ENO
26
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/26 Joins over unions Reduction for DHF Elimination of the empty intermediate relations (left sub-tree) ASG 1 EMP 2 TITLE=“Mech. Eng.” ASG 2 TITLE=“Mech. Eng.” ASG 2 EMP 2 TITLE=“Mech. Eng.” ⋈ ENO
27
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/27 Reduction for Hybrid Fragmentation Combine the rules already specified: ➡ Remove empty relations generated by contradicting selections on horizontal fragments; ➡ Remove useless relations generated by projections on vertical fragments; ➡ Distribute joins over unions in order to isolate and remove useless joins.
28
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/28 Reduction for HF Example Consider the following hybrid fragmentation: EMP 1 = ENO≤"E4" ( ENO,ENAME (EMP)) EMP 2 = ENO>"E4" ( ENO,ENAME (EMP)) EMP 3 = ENO,TITLE (EMP) and the query SELECTENAME FROMEMP WHEREENO="E5" EMP 1 EMP 2 EMP 3 ENO=“E5” ENAME EMP 2 ENO=“E5” ENAME ⋈ ENO
29
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/29 Outline Introduction Background Distributed Database Design Database Integration Semantic Data Control Distributed Query Processing ➡ Overview ➡ Query decomposition and localization ➡ Distributed query optimization Multidatabase Query Processing Distributed Transaction Management Data Replication Parallel Database Systems Distributed Object DBMS Peer-to-Peer Data Management Web Data Management Current Issues
30
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/30 Step 3 – Global Query Optimization Input: Fragment query Find the best (not necessarily optimal) global schedule ➡ Minimize a cost function ➡ Distributed join processing ✦ Bushy vs. linear trees ✦ Which relation to ship where? ✦ Ship-whole vs ship-as-needed ➡ Decide on the use of semijoins ✦ Semijoin saves on communication at the expense of more local processing. ➡ Join methods ✦ nested loop vs ordered joins (merge join or hash join)
31
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/31 Cost-Based Optimization Solution space ➡ The set of equivalent algebra expressions (query trees). Cost function (in terms of time) ➡ I/O cost + CPU cost + communication cost ➡ These might have different weights in different distributed environments (LAN vs WAN). ➡ Can also maximize throughput Search algorithm ➡ How do we move inside the solution space? ➡ Exhaustive search, heuristic algorithms (iterative improvement, simulated annealing, genetic,…)
32
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/32 Cost Functions Total Time (or Total Cost) ➡ Reduce each cost (in terms of time) component individually ➡ Do as little of each cost component as possible ➡ Optimizes the utilization of the resources Increases system throughput Response Time ➡ Do as many things as possible in parallel ➡ May increase total time because of increased total activity
33
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/33 Total Cost Summation of all cost factors Total cost= CPU cost + I/O cost + communication cost CPU cost= unit instruction cost no.of instructions I/O cost = unit disk I/O cost no. of disk I/Os communication cost = message initiation + transmission
34
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/34 Total Cost Factors Wide area network ➡ Message initiation and transmission costs high ➡ Local processing cost is low (fast mainframes or minicomputers) ➡ Ratio of communication to I/O costs = 20:1 Local area networks ➡ Communication and local processing costs are more or less equal ➡ Ratio = 1:1.6
35
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/35 Response Time Elapsed time between the initiation and the completion of a query Response time= CPU time + I/O time + communication time CPU time= unit instruction time * no. of sequential instructions I/O time= unit I/O time * no. of sequential I/Os communication time = unit msg initiation time * no. of sequential msg + unit transmission time * no. of sequential bytes
36
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/36 Example Assume that only the communication cost is considered Total time = 2 message initialization time + unit transmission time * ( x+y ) Response time = max {time to send x from 1 to 3, time to send y from 2 to 3} time to send x from 1 to 3 = message initialization time + unit transmission time * x time to send y from 2 to 3 = message initialization time + unit transmission time * y Site 1 Site 2 x units y units Site 3
37
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/37 Optimization Statistics Primary cost factor: size of intermediate relations ➡ Need to estimate their sizes Make them precise more costly to maintain Simplifying assumption: uniform distribution of attribute values in a relation
38
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/38 Join Ordering in Fragment Queries Ordering joins ➡ Distributed INGRES ➡ System R* ➡ Two-step Semijoin ordering ➡ SDD-1
39
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/39 Join Ordering Multiple relations more difficult because too many alternatives. ➡ Compute the cost of all alternatives and select the best one. ✦ Necessary to compute the size of intermediate relations which is difficult. ➡ Use heuristics R if size(R) < size(S) if size(R) > size(S) S Consider two relations only
40
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/40 Join Ordering – Example Consider PROJ ⋈ PNO ASG ⋈ ENO EMP Site 2 Site 3Site 1 PNO ENO PROJ ASG EMP
41
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/41 Join Ordering – Example Execution alternatives: 1.EMP Site 22.ASG Site 1 Site 2 computes EMP'=EMP ⋈ ASGSite 1 computes EMP'=EMP ⋈ ASG EMP' Site 3EMP' Site 3 Site 3 computes EMP' ⋈ PROJSite 3 computes EMP’ ⋈ PROJ 3.ASG Site 34.PROJ Site 2 Site 3 computes ASG'=ASG ⋈ PROJSite 2 computes PROJ'=PROJ ⋈ ASG ASG' Site 1PROJ' Site 1 Site 1 computes ASG' ▷◁ EMPSite 1 computes PROJ' ⋈ EMP 5.EMP Site 2 PROJ Site 2 Site 2 computes EMP ⋈ PROJ ⋈ ASG
42
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/42 Semijoin Algorithms Consider the join of two relations: ➡ R [ A ] (located at site 1) ➡ S [ A ](located at site 2) Alternatives: 1.Do the join R ⋈ A S 2.Perform one of the semijoin equivalents R ⋈ A S ( R ⋉ A S ) ⋈ A S R ⋈ A ( S ⋉ A R ) ( R ⋉ A S ) ⋈ A ( S ⋉ A R )
43
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/43 Semijoin Algorithms Perform the join ➡ send R to Site 2 ➡ Site 2 computes R ⋈ A S Consider semijoin ( R ⋉ A S ) ⋈ A S ➡ S' = A ( S ) ➡ S' Site 1 ➡ Site 1 computes R' = R ⋉ A S' ➡ R' Site 2 ➡ Site 2 computes R' ⋈ A S Semijoin is better if size ( A ( S )) + size ( R ⋉ A S )) < size ( R )
44
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/44 Dynamic Algorithm - INGRES Decompose each multi-variable query into a sequence of mono-variable queries with a common variable Process each by a one variable query processor ➡ Choose an initial execution plan (heuristics) ➡ Order the rest by considering intermediate relation sizes No statistical information is maintained
45
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/45 Dynamic Algorithm– Decomposition Replace an n variable query q by a series of queries q 1 q 2 … q n where q i uses the result of q i -1. Detachment ➡ Query q decomposed into q' q" where q' and q" have a common variable which is the result of q' Tuple substitution ➡ Replace the value of each tuple with actual values and simplify the query q ( V 1, V 2,... V n ) ( q' ( t 1, V 2, V 2,..., V n ), t 1 V 1 )
46
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/46 Detachment q : SELECTV 2.A 2,V 3.A 3, …,V n.A n FROMR 1 V 1, …,R n V n WHEREP 1 (V 1.A 1 ’ )AND P 2 (V 1.A 1,V 2.A 2,…, V n.A n ) q' : SELECTV 1.A 1 INTO R 1 ' FROMR 1 V 1 WHEREP 1 (V 1.A 1 ’ ) q" : SELECTV 2.A 2, …,V n.A n FROMR 1 ' V 1, R 2 V 2, …,R n V n WHEREP 2 (V 1.A 1, V 2.A 2, …,V n.A n )
47
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/47 Detachment Example Names of employees working on CAD/CAM project q 1 : SELECTEMP.ENAME FROMEMP, ASG, PROJ WHEREEMP.ENO=ASG.ENO ANDASG.PNO=PROJ.PNO ANDPROJ.PNAME="CAD/CAM" q 11 : SELECTPROJ.PNO INTO JVAR FROMPROJ WHEREPROJ.PNAME="CAD/CAM" q' : SELECTEMP.ENAME FROMEMP,ASG,JVAR WHEREEMP.ENO=ASG.ENO ANDASG.PNO=JVAR.PNO
48
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/48 Detachment Example (cont’d) q' : SELECTEMP.ENAME FROMEMP,ASG,JVAR WHEREEMP.ENO=ASG.ENO AND ASG.PNO=JVAR.PNO q 12 : SELECTASG.ENO INTO GVAR FROMASG,JVAR WHEREASG.PNO=JVAR.PNO q 13 : SELECTEMP.ENAME FROMEMP,GVAR WHEREEMP.ENO=GVAR.ENO
49
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/49 Tuple Substitution q 11 is a mono-variable query q 12 and q 13 is subject to tuple substitution Assume GVAR has two tuples only: 〈 E1 〉 and 〈 E2 〉 Then q 13 becomes q 131 : SELECTEMP.ENAME FROMEMP WHEREEMP.ENO="E1" q 132 : SELECTEMP.ENAME FROMEMP WHEREEMP.ENO="E2"
50
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/50 Distributed Dynamic Algorithm 1.Execute all monorelation queries (e.g., selection, projection) 2.Reduce the multirelation query to produce irreducible subqueries q 1 q 2 … q n such that there is only one relation between q i and q i +1 3.Choose q i involving the smallest fragments to execute (call MRQ') 4.Find the best execution strategy for MRQ' 3. Determine processing site 4. Determine fragments to move 5.Repeat 3 and 4
51
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/51 Static Approach – System R* Cost function includes local processing as well as transmission Considers only joins “Exhaustive” search Compilation Published papers provide solutions to handling horizontal and vertical fragmentations but the implemented prototype does not
52
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/52 Static Approach – Performing Joins Ship whole ➡ Larger data transfer ➡ Smaller number of messages ➡ Better if relations are small Fetch as needed ➡ Number of messages = O (cardinality of external relation) ➡ Data transfer per message is minimal ➡ Better if relations are large and the selectivity is good
53
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/53 Static Approach – Joins 1.Move outer relation tuples to the site of the inner relation (a)Retrieve outer tuples (b)Send them to the inner relation site (c)Join them as they arrive Total Cost = cost(retrieving qualified outer tuples) +no. of outer tuples fetched * cost(retrieving qualified inner tuples) + msg. cost * (no. outer tuples fetched * avg. outer tuple size)/msg. size
54
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/54 Static Approach – Joins 2.Move inner relation to the site of outer relation Cannot join as they arrive; they need to be stored Total cost=cost(retrieving qualified outer tuples) +no. of outer tuples * cost(retrieving matching inner tuples from temporary storage) +cost(retrieving qualified inner tuples) +cost(storing all qualified inner tuples in temporary storage) +msg. cost * no. of inner tuples fetched * avg. inner tuple size/msg. size
55
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/55 Static Approach – Joins 3.Move both inner and outer relations to another site Total cost=cost(retrieving qualified outer tuples) + cost(retrieving qualified inner tuples) + cost(storing inner tuples in storage) + msg. cost (no. of outer tuples fetched * avg. outer tuple size)/msg. size + msg. cost * (no. of inner tuples fetched * avg. inner tuple size)/msg. size + no. of outer tuples fetched * cost(retrieving inner tuples from temporary storage)
56
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/56 Static Approach – Joins 4.Fetch inner tuples as needed (a)Retrieve qualified tuples at outer relation site (b)Send request containing join column value(s) for outer tuples to inner relation site (c)Retrieve matching inner tuples at inner relation site (d)Send the matching inner tuples to outer relation site (e)Join as they arrive Total Cost=cost(retrieving qualified outer tuples) + msg. cost * (no. of outer tuples fetched) + no. of outer tuples fetched * no. of inner tuples fetched * avg. inner tuple size * msg. cost / msg. size) + no. of outer tuples fetched * cost(retrieving matching inner tuples for one outer value)
57
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/57 Dynamic vs. Static vs Semijoin Semijoin ➡ SDD1 selects only locally optimal schedules Dynamic and static approaches have the same advantages and drawbacks as in centralized case ➡ But the problems of accurate cost estimation at compile-time are more severe ✦ More variations at runtime ✦ Relations may be replicated, making site and copy selection important Hybrid optimization ➡ Choose-plan approach can be used ➡ 2-step approach simpler
58
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/58 2-Step Optimization 1.At compile time, generate a static plan with operation ordering and access methods only 2.At startup time, carry out site and copy selection and allocate operations to sites
59
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/59 2-Step – Problem Definition Given ➡ A set of sites S = { s 1, s 2, …, s n } with the load of each site ➡ A query Q = { q 1, q 2, q 3, q 4 } such that each subquery q i is the maximum processing unit that accesses one relation and communicates with its neighboring queries ➡ For each q i in Q, a feasible allocation set of sites S q = { s 1, s 2, …, s k } where each site stores a copy of the relation in q i The objective is to find an optimal allocation of Q to S such that ➡ the load unbalance of S is minimized ➡ The total communication cost is minimized
60
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/60 2-Step Algorithm For each q in Q compute load ( S q ) While Q not empty do 1. Select subquery a with least allocation flexibility 2. Select best site b for a (with least load and best benefit) 3. Remove a from Q and recompute loads if needed The benefit depends on the subqueries already allocated to the same site, which leads to communication cost savings.
61
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/61 2-Step Algorithm Example Let Q = { q 1, q 2, q 3, q 4 } where q 1 is associated with R 1, q 2 is associated with R 2 joined with the result of q 1, etc. Iteration 1: select q 4, allocate to s 1, set load( s 1 )=2 Iteration 2: select q 2, allocate to s 2, set load( s 2 )=3 Iteration 3: select q 3, allocate to s 1, set load( s 1 ) =3 Iteration 4: select q 1, allocate to s 3 or s 4 Note: if in iteration 2, q 2, were allocated to s 4, this would have produced a better plan. So hybrid optimization can still miss optimal plans
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.