QueryOptimization Siao
QueryOptimization Siao
CS 157B
Ch. 14
Mien Siao
Outline
Introduction
Steps in Cost-based query optimization- Query
Flow
Projection Example
Query Interaction in DBMS
Cost-based query Optimization: Algebraic
Expressions
Introduction
What is Query Optimization?
Suppose you were given a chance to
visit 15 pre-selected different cities
in Europe. The only constraint would
be Time
-> Would you have a plan to visit
the cities in any order?
Europe
Plan:
-> Place the 15 cities in different groups
based on their proximity to each other.
-> Start with one group and move on to the
next group.
1. Parsing
2. Transformation
3. Implementation
4. Plan selection based on cost
estimates
Query Flow
SQL
Parser
Optimizer
Code
Generator/
Interpreter
Processor
Query Parser Verify validity of the SQL
statement. Translate query into an internal
structure using relational calculus.
Query Optimizer Find the best expression
from various different algebraic expressions.
Criteria used is Cheapness
Code Generator/Interpreter Make calls for
the Query processor as a result of the work done
by the optimizer.
Query Processor Execute the calls obtained
from the code generator.
Cost of physical plans includes processor
time and communication time. The most
important factor to consider is disk I/Os
because it is the most time consuming
action.
Some other costs associated are:
- Operations (joins, unions,
intersections).
- The order of operations.
Why?
Joins, unions, and intersections are
associative and commutative.
- Management of storage of
arguments and passing of it.
filter
join
filter join
join Filter