by Markus Winand.

Optimizer - Query Optimizer - Query Planner


The Optimizer (Oracle), Query Optimizer (SQL Server, MySQL) or Query Planner (PostgreSQL) translates the SQL statement to an executable program, in form of an execution plan, very much like a compiler translates source code into an executable.

There are generally two kinds of Optimizers:

Rule Based Optimizer (RBO)

Rule Based Optimizers follow a strict set of rules to create an execution plan — e.g., always use an index if possible.

Cost Based Optimizer (CBO)

Cost Based Optimizers generate many different execution plans, apply a cost model to all of them and select the one with the best cost value for execution.

Cost Based Optimizers will, for example, compare the estimated cost for a query using an index to the cost reading the entire table. The optimizer may select the full table access if it the cost values suggest that the full table access is more efficient than the index lookup.

Cost Based Optimizers are the predominant implementation.

The major decisions done by Optimizers are:

  • Join Algorithm and Join Order selection

  • Index usage

Optimizers do not:

  • Optimize Tables or Indexes

  • Optimize obfuscated SQL

  • Defragment data

About the Author

Photo of Markus Winand

Markus Winand teaches efficient SQL—inhouse and online. He minimizes the development time using modern SQL and optimizes the runtime with smart indexing. His book entitled SQL Performance Explained has become standard reading.

Buy his Book on Amazon

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy on Amazon
(paperback only)

Paperback and PDF also available at Markus’ store.

Hire Markus

The quick and easy way to benefit from his extensive knowledge and experience.
Learn more »

“Use The Index, Luke!” by Markus Winand is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.
Legal | Contact | NO WARRANTY | Trademarks | Privacy | CC-BY-NC-ND 3.0 license