How does SQL Server handle queries arriving at the database engine?

Source: Internet
Author: User

When a query arrives at the database engine,SQL ServerPerform two major steps to generate the expected query results. The first step is query compilation, which generates the query plan, and the second step executes the query plan.

 

SQL Server 2005The query compilation in consists of three steps:Analysis and AlgebraAndQuery Optimization. After completing these steps, the compiler saves the optimized query plan to the process cache. Here, the execution engine converts the Plan into an executable form, and then executes the steps to generate the query results. If the plan is included in the process cache when the same query or stored procedure is executed again in the future, skip the compilation step and reuse the cached plan to execute the query or stored procedure.

 

about SQL server optimization :

SQL Server Does not optimize each statement in the batch processing. Only statements that access tables and may generate multiple execution plans are optimized. SQL Server Optimize all DML ( Data Operation Language ) Statement , That is Select , Delect And Update Statement. Besides DML , Others T-SQL The statement will also be optimized, Create Index This is one of them. Only the optimized statements generate a query plan.

about SQL groups in :

Group Or Having Explicit clauses such Select The only factor that the list is grouped.According SQL As long as an aggregate function bound to a specific list appears Group Or Having Clause also causes Select List Group . The following is a simple example:

Select C1, max (C2) from DBO. T1;

This isGroup Select ,Because the query contains Max Aggregation . Because it is a group Select , Where non-clustered columns are used C1 is invalid, so the query is incorrect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.