Show TOC

How SQL Statements Are ProcessedLocate this document in the navigation structure


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 specified in the SQL statement.

The SQL optimizer is responsible for determining the best search strategy for accessing the data.


  1. A database user or a database application sends an SQL statement with a search condition to the database.

    SELECT * FROM hotel.customer

      WHERE name BETWEEN 'B' AND 'P' AND firstname = 'Greg'

  2. The database system transforms the SQL statement to the most suitable form and 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.
  4. The SQL optimizer estimates the costs for each search strategy using statistical information on the database tables.
  5. The SQL optimizer chooses the search strategy that incurs the lowest costs when executing the SQL statement.
  6. The database system executes the SQL statement with this search strategy.