Two methods for obtaining execution plans in SQLSERVER

Source: Internet
Author: User

There are two ways to get the execution plan:
1. One is to enable some switches in front of the command to put the execution plan information in the result set. This method is suitable for tuning a single statement in a test environment.
These switches are most commonly used
Copy codeThe Code is as follows:
SET SHOWPLAN_ALL ON
SET SHOWPLAN_ALL ON -- (whether an execution plan is reused, does SQSERVERL feel that the index is missing?), which can only be seen in the XML output
SET STATISTICS PROFILE ON

If SSMS is used, you can press Ctrl + L in lower case to execute your statement and display the execution plan, but no result set is returned.
 
2. Another method is to use event tracking in SQL Trace to track the statement execution plan.
Common events include showplan all, showplan statistics profile, and showplan xml statistics profile.
The advantage of this method is that you do not need to turn on any switch and can be used to directly track application statement execution.
The disadvantage is that he will capture all the statements. If SQLSERVER is busy, the output will be large and may affect the performance. Therefore, use it with caution.
--------------------------------------------------------------------------------
Most of the information collected by the two methods is the same. The XML method returns the results in XML structure. In SQL Trace, the results can display the execution plan and related information graphically.

This output method may be more friendly for simple statements in execution plans. However, for complex execution plans, if they are displayed in graphs, it is difficult for a single screen to be fully placed. Statistics for each step can only be displayed with the mouse clicked, I personally think it is not as easy as text output format.

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.