Untitled

<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.

1. Relational Algebra Equivalences


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

2. Logical Query Optimization


The goal is to increase the likelihood of enumerating the optimal plan in the search.

  1. Selection Optimizations
    1. Predicate Pushdown ā†’ Perform ļ¬lters as early as possible
    2. Reorder predicates so that the DBMS applies the most selective one ļ¬rst.
    3. Split Conjunctive Predicates ā†’ Breakup a complex predicate and pushing it down
    4. Replace Cartesian Products ā†’ Replace all Cartesian Products with inner joins using the join predicates.
  2. Projection Optimizations
    1. Projection Pushdown ā†’ Perform projections as early as possible to create smaller tuples and reduce intermediate results
    2. Project out all attributes except the ones requested or requires.

3. Nested Queries


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.

Untitled

Approach #2: Decompose