SQL Statement -> Query Optimization -> Awesome Query Plan
SQL Query -> Parser -> Query Optimization -> Query Execution Engine
Logical Operator: what they do e.g. selection join union, project, grouping
Physical Operator: how they do e.g. sequential scan, index scan nested loop join, sort-merge join, hash join, index join
- Enumerate logically equivalent plans by applying equivalent rules
- For each logically equivalent plan, enumerate all alternative physical query plans
- Estimate the cost of each of the alternative physical query plans
- Run the plan with lowest estimated overall cost
Select and Join operators commute with each other Join operator is associative Select operator distributes over Joins Project operator cascades
for selection, we have sequential scan, and index scan for join, we have nested loop join, sort-merge join, hash join, and index join
Estimate how many rows will satisfy a predicate such as movie.id = 1 Histogram are the standard technique used to estimate Selectivity factor for predicates on a single table