How Does a SQL Query Work?

Ümit Berber
Commits
Published in
6 min readMar 25, 2024

--

This text describes the process a sql query goes through in the sql server engine.

This Picture was created by Bing image Creator

The journey of a Select statement in sql sever is basically as follows:

  • The parser scans the SELECT expression and splits it into logical units such as keywords, expressions, operators and identifiers.
  • A query tree is created that describes the logical steps required to transform the source data into the format required by the result set.
  • The Query Optimizer analyzes the different ways to achieve the result. It then chooses the most optimal solution. The query tree is updated by saving this exact choice. This optimized version of the query tree is called the execution plan.
  • The relational engine executes the execution plan. As steps requiring data from tables are processed, the relational engine requests that the storage engine transfers data from the rowsets requested from the relational engine.
  • The relational engine returns the result set of data returned from the storage engine to the client.

Let us now examine the details of this journey.

The SQL Server Database Engine can process SQL query using Row mode execution or Batch mode execution processing modes.

Row mode execution

--

--