Professional Documents
Culture Documents
John Ortiz
Terms
DBMS has algorithms to implement relational
algebra expressions
SQL is a different kind of high level language;
specify what is wanted, not how it is obtained
Optimization not necessarily optimal, but
reasonably efficient
Techniques:
Heuristic rules
Cost estimation
Execution
DBMS Strategies
Answer Data
Optimizer
Runtime
Code Execution
Database
Generator plan
Processor
Lecture 19 Query Processing & Optim 3
An Example
Query:
Select B,D
From R,S
Where R.A = c and S.E = 2 and R.C=S.C
R S
A B C C D E
a 1 10 15 x 2 Answer
b 1 20 25 y 2 B D
c 2 25 32 y 3 2 y
d 2 10 10 z 1
e 3 26
R S
R S
Lecture 19 Query Processing & Optim 6
Query Evaluation
How to evaluate individual relational operation?
Selection: find a subset of rows in a table
Join: connecting tuples from two tables
Other operations: union, projection,
How to estimate cost of individual operation?
How does available buffer affect the cost?
How to evaluate a relational algebraic
expression?
Options:
Cross product followed by selection
R R.A = S.B S and S S.B = R.A R
Cost of Writing
MR S
Buffer
M=MR+MS+1
MS
Result
select Name
from Students
where Advisor in (
select PID
from Professors
where Dept = Computer Science);
<SFW>
Advisor <SFW>
Students <condition>
<tuple> in PID
Advisor Professors
Lecture 19 Query Processing & Optim 28
Example: A Logical Plan
Name
Replace IN with cross
Advisor=PID
product followed by
selection
Students PID
Dept=Computer Science
Professors
Lecture 19 Query Processing & Optim 29
Example: Improve Logical Plan
Students PID
Dept=Computer Science
Professors
Lecture 19 Query Processing & Optim 30
Example: Estimate Result Size
Name
Need to estimate size here
Advisor=PID
Students PID
Dept=Computer Science
Professors
Lecture 19 Query Processing & Optim 31
Example: A Physical plan
Parameters:
Join order, buffer size
Hash join Project attributes,
Students Professors
Also specify pipelining, one or two pass
algorithm, which index to use,