First practice of SQL Server performance optimization Execution Plan (1)

Source: Internet
Author: User

Since the last article was published, I have received a lot of attention from my friends. Many friends require more practices than pure theories. Indeed, I started to work out this series based on practical ideas! At the same time, in order to make everyone better understand and digest this knowledge, I will regularly give online video lectures on the content, and my friends can join this group: Workshop

The agenda is as follows:
  • Practice Overview
  • Graphic execution plan practice
  • Explanation of execution plan information
Practice Overview

The execution plan can help us write highly efficient T-SQL code, but also can find out the problem of the existing T-SQL Code, also can monitor the database! Of course, it is up to us to use the execution plan at the end. But no matter what, we first learn to parse the information contained in the execution plan. The fastest way to learn is practice. Next, let's start with a practice.

In order to make it easy to understand, the examples here are not too complex. As the course continues to deepen, the subsequent examples will become more and more complex. At the same time, if you want to work together, you may want to install SQL2005 or a later version, and remember to install the AdventureWorks database. For: http://msftdbprodsamples.codeplex.com

In addition, it should be noted that, due to the relationship between data, operations, and time in the database, the execution plan generated by running the script may be different from that generated by me, there is no problem!

Graphic execution plan practice

Next we will officially enter the topic to be discussed.

First, to allow us to view the execution plan, at least ensure that we are granted permissions when logging on to the database, as shown in the following statement:

 
 
  1. GRANT SHOWPLAN TO [username] 

To focus the discussion on the Execution Plan (estimation execution plan and actual execution plan), we run a simple query here, as shown in the following code:

 
 
  1. SELECT * FROM [dbo].[DatabaseLog]; 

Next, let's take a look at the estimated execution plan of this statement, as described in the previous article: The estimated execution plan is the plan produced by the metadata and cost analysis algorithms used by the optimizer, this plan is an analysis before the query statement execution!

Show estimated execution plan

We can display the estimated execution plan in the following ways:

The graphic estimation query plan displayed for the preceding query statements is as follows:

Display the execution query plan

Unlike the estimated execution plan, the actual execution plan is not generated by the optimizer, and the actual execution plan is generated by the underlying storage engine during execution, this plan contains a large amount of actual underlying data and related information.

We can use the following methods to obtain the actual execution plan:

The actual execution plan of the preceding query is as follows:

In the first day, we thought there was no difference between the two, but they contained many different data information.

Next, we will begin to interpret the graphic execution plan.


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.