You are on page 1of 7

Join Ordering in Fragment Queries

Join ordering is important in a centralized DBMS. Join ordering is even more important in distributed DDBMSs. R site j: “relation R is transferred to site j”
Site 2 ENO



1. 2. 3. 4. 5.

Site 1

Site 3

EMP site 2; site 2 computes EMP’, EMP’->site 3; site 3 computes the result. ASG->site 1: site 1 computes EMP’, EMP’>site 3; site 3 computes the result ASG->site 3; compute ASG’;ASG’->site 1 PROJ->site 2; compute PROJ’; PROJ’>site 1 EMP->site 2; PROJ->site 2; site 2 compute the join.

Approach I: Ordering joins without using semi-joins
•Distributed INGRES •R* (distributed version of system R)

R >< S
If size(R) < size(S) If size(S) < size(R)


•Ignore the transfer time for producing data at the result site. •Size(R): Total number of bytes for R Consider costs of all strategies and choose the best one


BA[i]=0 otherwise. a few tuples or R participate in the join) S’ can be minimized by encoding it in a bit array (BA). BA[i]=1 if h(value of S. h() is the hash function. Some Semi-Joins Alternatives PNO PNO ENO PROJ PNO ENO PROJ ASG EMP ASG EMP ASG EMP • ASG1=ASG SJ EMP • ASG11= (ASG SJ PROJ) SJ EMP • Complex: Most algorithms use single semi-joins rather than nested semi-joins 2 ..A)=i.e. R’ consists of tuples whose BA(h(value of R.Approach II: Use semi-joins Semijoin: Site 1 R >< A S ⇔ ( R SJ A S ) >< A S ⇔ R >< A (S SJ A R) ⇔ ( R SJ A S ) >< A (S SJ A R) R' = R SJ A S ' S’ S' = ΠA(S) result= R'><A S Site 2 Semijoin is better than join if size(R’)+size(S’)<Size(R) (i.A))=1.

5=attribute size and tuple size R* Input: A localized query tree. database statistics Tasks: Select join ordering. IO. 3=join selectivity factor. the join algorithm. CPU No 1. •Site of the 1st relation •Site of the 2nd relation •Site of the 3rd relation 3 .Comparison of Query Optimization Algorithms Alg. INGRES SDD-1 R* Opt.5 No Static Total cost #msg. Factors Msg Size I/O.4. msg size. Timing Dynamic Objective Response time or total cost Total cost Optm.3. 4 size of projection on each join attribute. locations of the relations. there are three candidate sites. 2=number of unique values per attribute. the access path for each fragment Select the sites of join results. Dist. CPU Msg size Network Topology General or broadcast Wide area point-topoint General or local SemiJoins No Stats 1 Fragments Horizontal Static Yes 1.2 No 1=relation cardinality. To join two relations. the method to transfer data between sites.

4 . fewer messages • Smaller relations. which selects the matching tuples and sends them back to the site of the outer relation. Pro vs Cons • Large data transfer. Ship Whole. Fetch-as-needed (use semi-join) The outer relation is scanned. Good when the relations are large and only a few matching tuples. The join value of each tuple is sent to the site of the inner relation.R* Intersite Data Transfer (1) 1. use ship-whole R* Intersite Data Transfer (2) 2. The entire relation is shipped to the join site.

Strategy 1: Ship-Whole of the entire outer relation to the site of the inner. Cost = LT (retrieve card(R) tuples of R) + CT (size(R)) + LT (retrieve s tuples from S)*card(R) Site 1 Site 2 Outer R inner S 5 .R (outer) joins S (inner) on attribute A LT(): Local processing time (I/O + CPU time) CT(): Communication time s: average number of tuples of S that match an R tuple Assumption: Ignore the cost of writing the result of the join. the outer tuples can be joined as they arrive.

Cost = LT (for retrieval of S) + CT ( size of S) + LT (store card(S) in T)+ LT (retrieve card(R) tuples from R)+ LT (for retrieve s tuples from T)*card(R) Mem Outer R T inner S Strategy 3: For each outer tuple. Cost = LT(retrieve card(R) tuples from R) + CT(length(A))*card(R)+ LT(retrieve s tuples from S)*card(R)+ CT(s*length(S))*card(R) 6 . fetch-asneeded of the inner tuples.Strategy 2: Ship-Whole of the entire inner relation to the site of the outer The inner tuples have to be stored in a temporary relation T.

Strategy 4: Ship Whole of both relations to the third site and compute the join there. There is an index on S.ENO. The outer relation is sent to the third site later and its tuples are joined with T as they arrive Cost = LT(retrieve card(S) tuples from S) + CT(size(S))+ LT(store card(S) tuples in T)+ LT(retrieve card(R) tuples from R)+ CT(size(R))+ LT(retrieve s tuples from T)*card(R) Example R Site 1 R is ASG2. Strategy 4: Ship-Whole R and S to a third site. (A) S Site 2 Strategy 1: Ship whole R to site of S (good when R<<S. Strategy 3: Fetch S as needed for each tuple of R (good when length(A) is small. S is EMP2. index on ENO can be used). few tuples match. index on ENO cannot be used. A localized query tree. 7 . index on ENO can be used). The inner relation is sent to the third site and stored as a temporary relation T. most costly because no other operations after the join. Assume communication cost is dominant. Strategy 2: Ship whole S to site of R (good when S<<R. need to store S).