Download presentation
Presentation is loading. Please wait.
Published byEvelin Fallis Modified over 10 years ago
1
Distributed DBMSPage 7-9. 1© 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database Design Semantic Data Control Distributed Query Processing à Query Processing Methodology à Distributed Query Optimization Distributed Transaction Management o Parallel Database Systems o Distributed Object DBMS o Database Interoperability o Current Issues
2
Distributed DBMSPage 7-9. 2© 1998 M. Tamer Özsu & Patrick Valduriez Query Processing high level user query query processor low level data manipulation commands
3
Distributed DBMSPage 7-9. 3© 1998 M. Tamer Özsu & Patrick Valduriez Query Processing Components Query language that is used à SQL: “intergalactic dataspeak” Query execution methodology à The steps that one goes through in executing high- level (declarative) user queries. Query optimization à How do we determine the “best” execution plan?
4
Distributed DBMSPage 7-9. 4© 1998 M. Tamer Özsu & Patrick Valduriez SELECTENAME FROMEMP,ASG WHEREEMP.ENO = ASG.ENO ANDDUR > 37 Strategy 1 ENAME ( DUR>37 EMP.ENO=ASG.ENO (EMP ASG)) Strategy 2 ENAME (EMP ENO ( DUR>37 (ASG))) Strategy 2 avoids Cartesian product, so is “better” Selecting Alternatives
5
Distributed DBMSPage 7-9. 5© 1998 M. Tamer Özsu & Patrick Valduriez What is the Problem? Site 1Site 2Site 3Site 4Site 5 EMP 1 = ENO≤“E3” (EMP)EMP 2 = ENO>“E3” (EMP) ASG 2 = ENO>“E3” (ASG) ASG 1 = ENO≤“E3” (ASG) Result Site 5 Site 1Site 2Site 3Site 4 ASG 1 EMP 1 EMP 2 ASG 2 result 2 =(EMP 1 EMP 2 ) ENO DUR>37 (ASG 1 ASG 1 ) Site 4 result = EMP 1 ’ EMP 2 ’ Site 3 Site 1Site 2 EMP 2 ’ =EMP 2 ENO ASG 2 ’ EMP 1 ’ =EMP 1 ENO ASG 1 ’ ASG 1 ’ = DUR>37 (ASG 1 )ASG 2 ’ = DUR>37 (ASG 2 ) Site 5 ASG 2 ’ ASG 1 ’ EMP 1 ’ EMP 2 ’
6
Distributed DBMSPage 7-9. 6© 1998 M. Tamer Özsu & Patrick Valduriez Assume: à size (EMP) = 400, size (ASG) = 1000 à tuple access cost = 1 unit; tuple transfer cost = 10 units Strategy 1 produce ASG': (10+10) tuple access cost 20 transfer ASG' to the sites of EMP: (10+10) tuple transfer cost 200 produce EMP': (10+10) tuple access cost 2 40 transfer EMP' to result site: (10+10) tuple transfer cost 200 Total cost 460 Strategy 2 transfer EMP to site 5:400 tuple transfer cost 4,000 transfer ASG to site 5 :1000 tuple transfer cost 10,000 produce ASG':1000 tuple access cost 1,000 join EMP and ASG':400 20 tuple access cost 8,000 Total cost23,000 Cost of Alternatives
7
Distributed DBMSPage 7-9. 7© 1998 M. Tamer Özsu & Patrick Valduriez Minimize a cost function I/O cost + CPU cost + communication cost These might have different weights in different distributed environments Wide area networks à communication cost will dominate low bandwidth low speed high protocol overhead à most algorithms ignore all other cost components Local area networks à communication cost not that dominant à total cost function should be considered Can also maximize throughput Query Optimization Objectives
8
Distributed DBMSPage 7-9. 8© 1998 M. Tamer Özsu & Patrick Valduriez Assume à relations of cardinality n à sequential scan Complexity of Relational Operations OperationComplexity Select Project (without duplicate elimination) O( n ) Project (with duplicate elimination) Group O( n log n ) Join Semi-join Division Set Operators O( n log n ) Cartesian ProductO( n 2 )
9
Distributed DBMSPage 7-9. 9© 1998 M. Tamer Özsu & Patrick Valduriez Query Optimization Issues – Types of Optimizers Exhaustive search à cost-based à optimal à combinatorial complexity in the number of relations Heuristics à not optimal à regroup common sub-expressions à perform selection, projection first à replace a join by a series of semijoins à reorder operations to reduce intermediate relation size à optimize individual operations
10
Distributed DBMSPage 7-9. 10© 1998 M. Tamer Özsu & Patrick Valduriez Query Optimization Issues – Optimization Granularity Single query at a time à cannot use common intermediate results Multiple queries at a time à efficient if many similar queries à decision space is much larger
11
Distributed DBMSPage 7-9. 11© 1998 M. Tamer Özsu & Patrick Valduriez Query Optimization Issues – Optimization Timing Static compilation optimize prior to the execution difficult to estimate the size of the intermediate results error propagation à can amortize over many executions à R* Dynamic à run time optimization à exact information on the intermediate relation sizes à have to reoptimize for multiple executions à Distributed INGRES Hybrid à compile using a static algorithm à if the error in estimate sizes > threshold, reoptimize at run time à MERMAID
12
Distributed DBMSPage 7-9. 12© 1998 M. Tamer Özsu & Patrick Valduriez Query Optimization Issues – Statistics Relation à cardinality à size of a tuple à fraction of tuples participating in a join with another relation Attribute à cardinality of domain à actual number of distinct values Common assumptions à independence between different attribute values à uniform distribution of attribute values within their domain
13
Distributed DBMSPage 7-9. 13© 1998 M. Tamer Özsu & Patrick Valduriez Query Optimization Issues – Decision Sites Centralized à single site determines the “best” schedule à simple à need knowledge about the entire distributed database Distributed à cooperation among sites to determine the schedule à need only local information à cost of cooperation Hybrid à one site determines the global schedule à each site optimizes the local subqueries
14
Distributed DBMSPage 7-9. 14© 1998 M. Tamer Özsu & Patrick Valduriez Query Optimization Issues – Network Topology Wide area networks (WAN) – point-to-point à characteristics low bandwidth low speed high protocol overhead à communication cost will dominate; ignore all other cost factors à global schedule to minimize communication cost à local schedules according to centralized query optimization Local area networks (LAN) à communication cost not that dominant à total cost function should be considered à broadcasting can be exploited (joins) à special algorithms exist for star networks
15
Distributed DBMSPage 7-9. 15© 1998 M. Tamer Özsu & Patrick Valduriez Distributed Query Processing Methodology Calculus Query on Distributed Relations CONTROL SITE LOCAL SITES Query Decomposition Query Decomposition Data Localization Data Localization Algebraic Query on Distributed Relations Global Optimization Global Optimization Fragment Query Local Optimization Local Optimization Optimized Fragment Query with Communication Operations Optimized Local Queries GLOBAL SCHEMA GLOBAL SCHEMA FRAGMENT SCHEMA FRAGMENT SCHEMA STATS ON FRAGMENTS STATS ON FRAGMENTS LOCAL SCHEMAS LOCAL SCHEMAS
16
Distributed DBMSPage 7-9. 16© 1998 M. Tamer Özsu & Patrick Valduriez 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
17
Distributed DBMSPage 7-9. 17© 1998 M. Tamer Özsu & Patrick Valduriez 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 Normalization
18
Distributed DBMSPage 7-9. 18© 1998 M. Tamer Özsu & Patrick Valduriez 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 Analysis
19
Distributed DBMSPage 7-9. 19© 1998 M. Tamer Özsu & Patrick Valduriez 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 Analysis – Example 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
20
Distributed DBMSPage 7-9. 20© 1998 M. Tamer Özsu & Patrick Valduriez If the query graph is not connected, the query is wrong. SELECTENAME,RESP FROMEMP, ASG, PROJ WHEREEMP.ENO = ASG.ENO ANDPNAME = "CAD/CAM" ANDDUR ≥ 36 ANDTITLE = "Programmer" Analysis PNAME=“CAD/CAM” ENAME RESULT RESP ASGPROJEMP
21
Distributed DBMSPage 7-9. 21© 1998 M. Tamer Özsu & Patrick Valduriez 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 p 1 … à application of transitivity à use of integrity rules Simplification
22
Distributed DBMSPage 7-9. 22© 1998 M. Tamer Özsu & Patrick Valduriez 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” Simplification – Example
23
Distributed DBMSPage 7-9. 23© 1998 M. Tamer Özsu & Patrick Valduriez 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) Restructuring ENAME DUR=12 OR DUR=24 PNAME=“CAD/CAM” ENAME≠“J. DOE” PROJASGEMP Project Select Join PNO ENO
24
Distributed DBMSPage 7-9. 24© 1998 M. Tamer Özsu & Patrick Valduriez 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 Restructuring – Transformation Rules
25
Distributed DBMSPage 7-9. 25© 1998 M. Tamer Özsu & Patrick Valduriez 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 ) B ’ ( S ) C ( R ( A j,B k ) S ) A ’ ( R ) ( A j,B k ) B ’ ( S ) C ( R S ) C ( R ) C ( S ) where R [ A ] and S [ B ]; C = A ' B ' where A' A, B' B Restructuring – Transformation Rules
26
Distributed DBMSPage 7-9. 26© 1998 M. Tamer Özsu & Patrick Valduriez 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. SELECTENAME 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 OR DUR=24 PNAME=“CAD/CAM” ENAME≠“J. DOE” PROJASGEMP Project Select Join PNO ENO
27
Distributed DBMSPage 7-9. 27© 1998 M. Tamer Özsu & Patrick Valduriez Equivalent Query ENAME PNAME=“CAD/CAM” (DUR=12 DUR=24) ENAME≠“J. DOE” PROJASGEMP PNO ENO
28
Distributed DBMSPage 7-9. 28© 1998 M. Tamer Özsu & Patrick Valduriez EMP ENAME ENAME ≠ "J. Doe" ASGPROJ PNO,ENAME PNAME = "CAD/CAM" PNO DUR =12 DUR=24 PNO,ENO PNO,ENAME Restructuring PNO ENO
29
Distributed DBMSPage 7-9. 29© 1998 M. Tamer Özsu & Patrick Valduriez 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
30
Distributed DBMSPage 7-9. 30© 1998 M. Tamer Özsu & Patrick Valduriez 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 OR DUR=24 PNAME=“CAD/CAM” ENAME≠“J. DOE” PROJ EMP 1 EMP 2 EMP 3 ASG 1 ASG 2 PNO ENO
31
Distributed DBMSPage 7-9. 31© 1998 M. Tamer Özsu & Patrick Valduriez Provides Parallellism EMP 3 ASG 1 EMP 2 ASG 2 EMP 1 ASG 1 EMP 3 ASG 2 ENO
32
Distributed DBMSPage 7-9. 32© 1998 M. Tamer Özsu & Patrick Valduriez Eliminates Unnecessary Work EMP 2 ASG 2 EMP 1 ASG 1 EMP 3 ASG 2 ENO
33
Distributed DBMSPage 7-9. 33© 1998 M. Tamer Özsu & Patrick Valduriez 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” Reduction for PHF ENO=“E5” EMP 1 EMP 2 EMP 3 EMP 2 ENO=“E5”
34
Distributed DBMSPage 7-9. 34© 1998 M. Tamer Özsu & Patrick Valduriez 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 )) Reduction for PHF
35
Distributed DBMSPage 7-9. 35© 1998 M. Tamer Özsu & Patrick Valduriez Reduction with join - Example à 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 Reduction for PHF EMP 1 EMP 2 EMP 3 ASG 1 ASG 2 ENO
36
Distributed DBMSPage 7-9. 36© 1998 M. Tamer Özsu & Patrick Valduriez Reduction with join - Example à Distribute join over unions à Apply the reduction rule Reduction for PHF EMP 1 ASG 1 EMP 2 ASG 2 EMP 3 ASG 2 ENO
37
Distributed DBMSPage 7-9. 37© 1998 M. Tamer Özsu & Patrick Valduriez 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 Reduction for VF ENAME EMP 1 EMP 2 ENAME ENO
38
Distributed DBMSPage 7-9. 38© 1998 M. Tamer Özsu & Patrick Valduriez 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.” Reduction for DHF
39
Distributed DBMSPage 7-9. 39© 1998 M. Tamer Özsu & Patrick Valduriez 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
40
Distributed DBMSPage 7-9. 40© 1998 M. Tamer Özsu & Patrick Valduriez Joins over unions Elimination of the empty intermediate relations (left sub-tree) Reduction for DHF ASG 1 EMP 2 TITLE=“Mech. Eng.” ASG 2 TITLE=“Mech. Eng.” ASG 2 EMP 2 TITLE=“Mech. Eng.” ENO
41
Distributed DBMSPage 7-9. 41© 1998 M. Tamer Özsu & Patrick Valduriez 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. Reduction for HF
42
Distributed DBMSPage 7-9. 42© 1998 M. Tamer Özsu & Patrick Valduriez 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” Reduction for HF EMP 1 EMP 2 EMP 3 ENO=“E5” ENAME EMP 2 ENO=“E5” ENAME ENO
43
Distributed DBMSPage 7-9. 43© 1998 M. Tamer Özsu & Patrick Valduriez 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)
44
Distributed DBMSPage 7-9. 44© 1998 M. Tamer Özsu & Patrick Valduriez 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,…)
45
Distributed DBMSPage 7-9. 45© 1998 M. Tamer Özsu & Patrick Valduriez Distributed Query Optimization Problems Cost model à multiple query optimization à heuristics to cut down on alternatives Larger set of queries à optimization only on select-project-join queries à also need to handle complex queries (e.g., unions, disjunctions, aggregations and sorting) Optimization cost vs execution cost tradeoff à heuristics to cut down on alternatives à controllable search strategies Optimization/reoptimization interval à extent of changes in database profile before reoptimization is necessary
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.