Prev: query-execution-ii Next: query-planning–optimization-ii
SQL is declarative, so the DBMS needs to generate the “best” plan for a given query.
Optimization is an NP-hard problem, so there’s no computationally cheap way to solve the optimization problem.
Thus, Heuristics and Cost-based search are some guiding principles to optimize queries.
The DBMS can rewrite an expression with a cheaper one if they generate the same set of tuples. Some examples:
Prev: query-execution-ii Next: query-planning–optimization-ii