Lecture11 Query Processing
Lecture11 Query Processing
Query Processing
Last Lecture…
Indexes
Any questions?
This Lecture…
Query Processing: Overview
What?
Why?
How? (Basics)
Query Processing
What happens to a query inside
the DBMS?
SELECT s.sname
FROM S, SP
WHERE S.sno = SP.sno AND
SP.pno = ‘P2’
Selection operator
Read 10,000 pages
Keep the result, 50 tuples in
memory
Join with S
Read 100 pages
Total cost 10,100 disk I/Os
Heuristic Optimization
A query can have many equivalent
query trees
Cascade of .
L1 ( L2 (… (Ln (E)…)) = L1 ( E )
Equivalence Rules…
(contd.)
Selections can be combined with
Cartesian products and theta joins.
a. ( E1 E2 ) E1 E2
Etc.
Equivalence Rules (contd.)
Equivalence rules states that two expressions are
equal
It does not state, which one is better
etc.
Indexes and cost of query
plans…
Using an index does not necessarily
mean efficient query plan.
Reserves:
Each tuple is 40 bytes long, 100 tuples per
page, 1000 pages.
Sailors:
Each tuple is 50 bytes long, 80 tuples per
page, 500 pages.
SELECT *
In algebra: R S.
Common! Must be carefully
optimized. R
S is large; so, R
selection is inefficient.
S followed by a
times.
With 100-page block of Sailors as outer:
Cost of scanning S is 500 I/Os; a total of 5 blocks.
Must estimate size of result for each operation in
tree!
Use information about the input relations.
For selections and joins, assume independence of
Statistics and Catalogs
Must estimate size of result and cost for each plan node.
Key issues: Statistics, indexes, operator implementations.