Monday 31 March 2014

SQL Tutorial: Query Processor

The query processor performs two basic functions

  • Query optimization
  • Query execution
Query optimization is one of the most complex tasks that Microsoft SQL Server does. The below definition and most of this information in this article has been minded from Kalen Delany's book.

The query processor is also called the relational engine, it determines exactly what your query needs to do and the best way to do it.

To perform the 2 basic tasks of query optimization and query processor has 3 components

sql tutorial


















  • Command Parser: The command parser performs syntax check on the query being worked on and raises a syntax error if it doesn't recognize the syntax. It also translates the commands into an internal format called the query tree.
  • Query Optimizer: The query optimizer works on the query tree produced by the command parser and prepares it for execution.Only DML commands (Select,Update,delete) are passed through as they can be processed in many different ways.The query optimizer compiles the commands, optimizes the parts which are optimizable, checks for security and creates an execution plan.
  • Query Executor: The query executor works on the execution plan given by the query optimizer.It steps through command by command and interacts with the storage engine for data manipulation, locking and managing transactions.
The query optimizer is "smart" in the sense that it users heuristics (common sense) to make sure that finding all possible execution plans and then deciding which one is better, should not take more than just picking up any random plan and executing it.

    SQL Server Query Execution Plans for beginners – Clustered Index Operators

    In this article we will continue discussing the various execution plan operators related to clustered indexes and what they do, when do the...