The Query Processor is the component inside the SQL Server Database Engine that is responsible for compiling a query. In this section, we will focus on the highlighted sections of the following diagram, which handle query compilation:
The first stage of query processing is generally known as query compilation and includes a series of tasks that will eventually lead to the creation of a query plan. When an incoming T-SQL statement is parsed to perform syntax validations and ensure that it is correct T-SQL, a query hash value representing that statement as it was written is generated. If that query hash is already mapped to a cached query plan, it can just attempt to reuse that plan. However, if a query plan for the incoming query is not already found in the cache, query compilation proceeds with the following tasks:
- Perform binding, which is the process...