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 is the SQL Renaissance Ambassador. He is on a mission to introduce developers to the evolution of SQL in the 21st century. Markus can be hired as trainer, speaker and consultant via

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

Markus offers SQL training and consulting for developers working at companies of any size.
Learn more »

Do not use offset for pagination

Learn why

Visit my sibling!A lot changed since SQL-92!

The Use The Index, Luke! mug

Stickers, coasters, books and coffee mugs. All you need for learning.

Shop now

Connect with Markus Winand

Markus Winand on LinkedInMarkus Winand on XINGMarkus Winand on Twitter
“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 and GDPR | CC-BY-NC-ND 3.0 license