SQL statements merely specify the results that are desired. They do not contain any information as to how the database system should search for the data. The database system can often choose from multiple options for finding the data required by the SQL statement.
The SQL Optimizer has the task of determining the best search strategy for accessing the data.
...
A user or a database application sends an SQL statement with a search conditionto the database.
1. The database system performs an automatic transformation of the SQL statement.
2. The database system starts the SQL Optimizer.
3. The SQL Optimizer determines all the search strategies with which the database can access the data specified in the SQL statement.
The SQL Optimizer determines the costs for every one of these search strategies. The SQL Optimizer requires statisticsto determine the best strategy for processing complex SQL statements.
The SQL Optimizer chooses the search strategythat incurs the lowest costs when executing the SQL statement.
4. The database system executes the SQL statement with this search strategy.
See also: