Execution plan helps in knowing how a query gets executed and troubleshooting a query which is performing poor.
In SQL Server execution plan can be of 2 types:
- Estimated Execution plan
- Actual Execution plan
Execution plan can be viewed in 3 different formats:
- Text format
- XML format
- Graphical format
We can choose the format on depending what level of details we want to see.
Let’s discuss these format one by one.
- Text format
Execution plan in text format can be seen using these 3 methods.
- Statistics Profile
Showplan_ALL : Its shows the estimated execution plan of the query. To enable it we need to execute the query:
SET SHOWPLAN_ALL ON;
Once we analyze our query plan we can turn off this option by executing below query so that our subsequent queries will not get affected from this.
SET SOWPLAN_ALL OFF;
Showplan_Text: It’s also works with the estimated execution plan of the query. To enable it we need to execute the query:
SET SHOWPLAN_TEXT ON;
SET SHOWPLAN_TEXT OFF;
Statistics Profile: It works with the actual execution plan. We need to execute the below query to enable it:
SET STATISTICS PROFILE ON;
SET STATISTICS PROFILE OFF;
2 XML format plans
Execution plan can be seen in XML format by using following two methods:
Statistics XML: It is used to generate the execution plan in XML format. After clicking on XML link a graphical execution plan gets opened in a new window. We can save that graphical plan to our local disk with extension .sqlplan.
Showplan XML: It’s also generates the XML plan and only one result set appears in outcome with XML link.
3. Graphical Plan
This is the most easiest and readable option to generate the execution plan. It also has two option for generating execution plan:
Estimated execution plan
Actual execution plan
To enable the estimated execution plan we can press the shortcut key Ctrl +L. Also, we can navigate to Query tab and select Display Estimated Execution Plan.
Estimated execution plan is beneficial when we have complex query and not aware how much it will take for complete execution in such situation we can use this as this doesn’t execute the query to generate the plan.
Similarly, actual execution plan we can be enabled by using shortcut key Ctrl+M.
We can also activate it by selecting option Include Actual Execution Plan from Query menu tab.
That’s all for the day folks.