Databases Reference
In-Depth Information
To check for a query plan, the Command Parser generates a hash of the T-SQL and checks it against
the plan cache to determine whether a suitable plan already exists. The plan cache is an area in the
buffer pool used to cache query plans. If it i nds a match, then the plan is read from cache and
passed on to the Query Executor for execution. (The following section explains what happens if it
doesn't i nd a match.)
Plan Cache
Creating execution plans can be time consuming and resource intensive, so it makes sense that if
SQL Server has already found a good way to execute a piece of code that it should try to reuse it for
subsequent requests.
The plan cache, part of SQL Server's buffer pool, is used to store execution plans in case they are
needed later. You can read more about execution plans and plan cache in Chapters 3 and 5.
If no cached plan is found, then the Command Parser generates a query tree based on the T-SQL. A
query tree is an internal structure whereby each node in the tree represents an operation in the query
that needs to be performed. This tree is then passed to the Query Optimizer to process. Our basic
query didn't have an existing plan so a query tree was created and passed to the Query Optimizer.
Figure 1-3 shows the plan cache added to the diagram, which is checked by the Command Parser for
an existing query plan. Also added is the query tree output from the Command Parser being passed
to the optimizer because nothing was found in cache for our query.
Query Tree
Language Event
TDS
Cmd Parser
Query Plan
SQL Server
Network Interface
Optimizer
Query Executor
SNI
Protocol
Layer
Relational Engine
Plan Cache
Data Cache
Bufer Pool
FIGURE 1-3
Search WWH ::




Custom Search