










Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!











Query Processing Overview
Query Optimization
Distributed Query Processing Steps
Acknowledgements:
I am indebted to Arturas Mazeika for providing me his slides of this course.
J. Gamper
Query Processing Overview
Query processing
: A 3-step process that transforms a high-level query (of relational
calculus/SQL) into an
equivalent
and
more efficient
lower-level query (of relational
algebra).
Parsing and translation
-
Check syntax and verify relations.
relational algebra expression.Translate the query into an equivalent
Optimization
-
(with lowest cost) for the query plan.Generate an optimal evaluation plan
Evaluation
-
query.plan, and returns the answers to the(optimal) evaluation plan, executes thatThe query-execution engine takes an
J. Gamper
Query Processing Example
Example:
Transformation of an SQL-query into an RA-query.
Query:Relations: EMP(ENO, ENAME, TITLE), ASG(ENO,PNO,RESP,DUR)
Find the names of employees who are managing a project
High level query
Expression 1:
EN AM E
DU R>
37
∧
EM P.EN O
=
ASG.EN O
Expression 2:
EN AM E
EN O
DU R>
37
therefore typically is better.Expression 2 avoids the expensive and large intermediate Cartesian product, and
J. Gamper
Query Processing Example...
We make the following assumptions about the data fragmentation
-
Site1:
EN O
≤
” E
3”
Site2:
EN O>
” E
3”
Site3:
EN O
≤
” E
3”
Site4:
EN O>
” E
3”
Site5: Result
Relations ASG and EMP are fragmented in the same way
respectivelyRelations ASG and EMP are locally clustered on attributes RESP and ENO,
J. Gamper
Query Processing Example...
Calculate the cost of the two strategies under the following assumptions:
-
Tuples are uniformly distributed to the fragments; 20 tuples satisfy
size(EMP) = 400, size(ASG) = 1000
tuple access cost = 1 unit; tuple transfer cost = 10 units
ASG and EMP have a local index on DUR and ENO
Strategy 1
-
Produce ASG’s: (10+10) * tuple access cost
20
-
Transfer ASG’s to the sites of EMPs: (10+10) * tuple transfer cost
200
-
Produce EMP’s: (10+10) * tuple access cost * 2
40
-
Transfer EMP’s to result site: (10+10) * tuple transfer cost
200
-
Total cost
460
Strategy 2
-
Transfer EMP
1
, EMP
2
to site 5: 400 * tuple transfer cost
4,
-
Transfer ASG
1
, ASG
2
to site 5: 1000 * tuple transfer cost
10,
-
Select tuples from ASG
1
ASG
2 : 1000 * tuple access cost
1,
-
Join EMP and ASG’: 400 * 20 * tuple access cost
8,
-
Total cost
23,
J. Gamper
Query Optimization
Query optimization
is a crucial and difficult part of the overall query processing
Objective of query optimization is to
minimize
the following cost function:
I/O cost
CPU cost
communication cost
Two different scenarios are considered:
-
Communication cost dominates
low bandwidth
low speed
high protocol overhead
Most algorithms ignore all other cost components
Communication cost not that dominant
Total cost function should be considered
J. Gamper
Query Optimization Issues
Several issues have to be considered in query optimization
Types of query optimizers
-
wrt the search techniques (exhaustive search, heuristics)
wrt the time when the query is optimized (static, dynamic)
Statistics
Decision sites
Network topology
Use of semijoins
J. Gamper
Query Optimization Issues...
Types of Query Optimizers wrt Search Techniques
-
Cost-based
Optimal
Combinatorial complexity in the number of relations
Not optimal
Regroups common sub-expressions
Performs selection, projection first
Replaces a join by a series of semijoins
Reorders operations to reduce intermediate relation size
Optimizes individual operations
J. Gamper
Query Optimization Issues...
Statistics
-
Cardinality
Size of a tuple
Fraction of tuples participating in a join with another relation/fragment
Cardinality of domain
Actual number of distinct values
Distribution of attribute values (e.g., histograms)
Independence between different attribute values
Uniform distribution of attribute values within their domain
J. Gamper
Query Optimization Issues...
Decision sites
-
Single site determines the ”best” schedule
Simple
Knowledge about the entire distributed database is needed
Cooperation among sites to determine the schedule
Only local information is needed
Cooperation comes with an overhead cost
One site determines the global schedule
Each site optimizes the local sub-queries
J. Gamper
Query Optimization Issues...
Use of Semijoins
-
Reduce the size of the join operands by first computing semijoins
Particularly relevant when the main cost is the communication cost
exchange between sitesImproves the processing of distributed join operations by reducing the size of data
However, the number of messages as well as local processing time is increased
J. Gamper
Distributed Query Processing Steps
J. Gamper