Advanced Database Management Systems: Query Processing: Chapter 1
Advanced Database Management Systems: Query Processing: Chapter 1
Systems
Examples from: Principles of Database Systems by Greg Riccardi, Addison Wesley, 2001
select * from Customer
where accountId = 101
select * from Customer
where accountId >= 101 and accountId < 300
select * from Customer where lastName < 'D'
Scanning,
SQL Expression Tree
Parsing,
Query (algebra)
Validating
Optimizer
Execution
Query Code Plan
Generator
Query DB Runtime
Result
Code Processor
Check syntax
Select * from Eployees having salary >1000
Check Schema Elements
Attributes, relations … used
Converts SQL to RA expression
Query optimization determines
the most efficient (or sufficiently efficient)
process for executing the query
Optimization reorganizes
an expression tree for a query
using algebraic transformation rules
Information used:
implementation techniques for algebra operators
algebraic transformation rules
heuristic rules
cost estimates
Commutative: σ ⋈ x ⋃ ⋂
Associative: ⋈ x ⋃ ⋂
Cascades of select:
σ c1 AND c2 AND … AND cn (R) ≡ σc1(σc2( … σcn(R))…))
selects can then be commuted
Cascades of project:
πL1(πL2( … πLn(R))…)) ≡ πL1(R)
projects cannot be commuted
Commuting select and project:
πA1,A2,…,An(σc(R)) ≡ σc(πA1,A2,…,An(R))
σc(R x S) ≡ R ⋈c S
Commuting select and join or cross-product:
σc(R ⋈ S) ≡ σc(R) ⋈ S
valid when selection condition involves only attributes in R
Employee e works_on w
πe.lname, e.fname, w.pno, w.hours
Employee e works_on w
πe.lname, e.fname, w.pno, w.hours
Heuristic:
Combine select
σw.hours > 20
and cross join
⋈e.ssn=w.essn
Employee e works_on w
πe.lname, e.fname, w.pno, w.hours
Heuristic:
Push selects as
early as possible ⋈e.ssn=w.essn
works_on w
πe.lname, e.fname, w.pno, w.hours
works_on w
πe.lname, e.fname, w.pno, w.hours
Heuristic:
⋈e.ssn=w.essn
Push projects as Push project
early as possible through join
Employee e
σw.hours > 20
works_on w
πe.lname, e.fname, w.pno, w.hours
Heuristic:
⋈e.ssn=w.essn
Push projects as Push project
early as possible through select
works_on w
At this point we’ve generated
nine different query plans for the same query