
There are two basic plans the optimiser might choose here: (The months_of_service column has a NOT NULL constraint on it and an ordinary index on it.) In general, one of the biggest contributors to a slow query is the number of rows read to service the query (blocks, to be more precise), so the cost will be based in part on the number of rows the optimiser estimates will need to be read.įor example, lets say you have the following query: SELECT emp_id FROM employees WHERE months_of_service = 6 (Note: in some cases the CBO does not have enough time to evaluate every possible plan in these cases it just picks the plan with the lowest cost found so far) The CBO calculates a relative Cost for each plan, then picks the plan with the lowest cost.

The COST is the final output of the Cost-based optimiser (CBO), the purpose of which is to select which of the many different possible plans should be used to run the query.

The output of EXPLAIN PLAN is a debug output from Oracle's query optimiser.
