Saturday, September 10, 2011

Query Plan



                   For each query, sql server creates a query plan that includes all the information required to return the data effectively. If the query is a stored procedure, this plan is stored in a cache when it is compiled, so that it can be used during subsequent executions.
          Only one user can access the plan at a time, if two users request the same query plan for stored procedure, sql server creates new, second plan and stores it in cache as well. This second plan might be different from the first one due to the integrity of the available indexes and data at the time of execution.

When your sql statement is first submitted to the sql server, it performs the following tasks.
1         Parses the raw sql code for any syntax errors to be reported.
2         Checks for aliases referenced in the from clause to be used later in the process and checks valid object references
3         Generates the query plan based on available data, statistics, and indexes
4         Compiles the query and places it into cache if it is a stored procedure
5         Executes the compiled query plan and returns the data to the client

No comments:

Post a Comment