<aside> š” Heuristics / Rules
Rewrite the query to remove stupid / inefficient things.
These techniques may need to examine catalog, but they do not need to examine data.
</aside>
<aside> š” Cost-based Search
Use a model to estimate the cost of executing a plan.
Evaluate multiple equivalent plans for a query and pick the one with the lowest cost.
</aside>
<aside> š” Logical plan roughly equivalent to the relational algebra expressions in the query.
The optimizer generates a mapping of a logical algebra expression to the optimal equivalent physical algebra expression.
</aside>
<aside> š” Physical plans may depend on the physical format of the data that is processed (i.e. sorting, compression).
Physical operators deļ¬ne a speciļ¬c execution strategy using an access path for the different operators in the query plan.
</aside>
There does not always exist a one-to-one mapping from logical to physical plans.
Two relational algebra expressions are equivalent if they generate the same set of tuples
Query Rewriting ā technique of transforming the underlying relational algebra representation of a logical plan
The goal is to increase the likelihood of enumerating the optimal plan in the search.
Approach #1: Rewrite
Re-write the query by de-correlating and / or ļ¬attening it.
Rewriting The former query can be rewritten as the latter query by rewriting the subquery as a JOIN. Removing a level of nesting in this way effectively ļ¬attens the query.
Approach #2: Decompose