Steps to process SELECT statement in SQL


There is no exact steps that the database server should use to retrieve the requested data as SELECT statement is non procedural. Database server optimizes the SELECT statement by analysing the statement to determine the most efficient way to extract the requested data.
The process of selecting one execution plan from potentially many possible plans is referred to as optimization. The query optimizer is one of the most important components of a SQL database system.

The input parameters to the query optimizer are:
  • query
  • the database schema (table and index definitions)
  • the database statistics
The output of the optimizer is a query execution plan, sometimes referred to as a query plan or just a plan.

Steps:

  1. The select statement is broken into logical units 
  2. A sequence tree is built based on the keywords and expressions in the form of the   logical units.
  3. Query optimizer checks for various permutations and combinations to figure out the fastest way using minimum resources to access the source tables. The best found way is called as an execution plan.
  4. Relational engine executes the plan and processes the data

Generally, there are different methods for accessing the data in each table. If only a few rows with specific key values are required, the database server can use an index. If all the rows in the table are required, the database server can ignore the indexes and perform a table scan. 

0 comments:

Post a Comment