SQLMentor // glossary

Query Optimizer

The query optimizer is the database component that decides how to actually execute a SQL statement — which indexes to use, which join algorithm, and what order to process tables in — based on table statistics, not on the order you wrote the SQL.

Most modern databases use a cost-based optimizer: it estimates the cost (roughly, I/O and CPU work) of several candidate execution plans and picks the cheapest one, using statistics about table size and data distribution. This is why keeping statistics up to date (ANALYZE, DBMS_STATS, UPDATE STATISTICS) matters so much — stale statistics lead the optimizer to bad decisions.

You influence the optimizer indirectly, through indexes, statistics, and schema design — direct "hints" exist but are a last resort, not a first move.