Query Processing refers to the steps a DBMS takes to transform a high-level query (typically SQL) into an efficient execution strategy to retrieve data from the database.
| Optimizer Type | Description |
|---|---|
| Rule-Based Optimizer (RBO) | Uses heuristic rules (e.g., push selections early). |
| Cost-Based Optimizer (CBO) | Uses statistics and cost models to estimate execution costs and choose the best plan. |
Uses equivalence rules to rewrite queries into alternative forms.
Example rules:
Important for multi-table queries.
Common join methods:
Deciding whether to use:
The optimizer estimates costs using statistics like:
Cost = Estimated I/O + CPU + Memory usage.
The output of query optimization is an execution plan describing:
Plans can be represented as trees where:
Suppose a query involves joining three tables: A, B, and C.
The optimizer considers different join orders:
It estimates the size of intermediate results and chooses the order minimizing cost.
| Query Processing Stage | Function |
|---|---|
| Parsing & Translation | Syntax check, query tree generation |
| Optimization | Find lowest cost query plan |
| Execution | Run query plan, retrieve results |
Open this section to load past papers