30.06.2013 Views

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Text and XML <strong>Execution</strong> <strong>Plans</strong> for Basic Queries<br />

Now, we'll capture the equivalent text plan. There is no button to turn on in the GUI to<br />

capture text plans. Instead, we'll use a T-<strong>SQL</strong> statement to output the text plan. Turning<br />

on SHOWPLAN_ALL will allow you to collect estimated execution plans. This is a change<br />

to the behavior of your query window. No T-<strong>SQL</strong> code submitted after this statement is<br />

actually executed until you turn SHOWPLAN_ALL off again.<br />

SET SHOWPLAN_ALL ON;<br />

GO<br />

SELECT e.BusinessEntityID ,<br />

e.JobTitle ,<br />

e.LoginID<br />

FROM HumanResources.Employee AS e<br />

WHERE e.LoginID = 'adventure-works\marc0';<br />

GO<br />

SET SHOWPLAN_ALL OFF;<br />

Listing 3.2<br />

By default, the text plan displays in a spreadsheet-style grid format, as shown in<br />

Figure 3.2. 1<br />

Figure 3.2<br />

The layout of the results of the text plan consists of rows of information where each row<br />

is an operator. The plan displays the operators in the logical processing order from top<br />

to bottom, similar to reading a graphical plan from left to right. In this example, Row 1 is<br />

the parent node, the first operator in the execution plan, and the StmtText column for<br />

this row contains the text for the T-<strong>SQL</strong> statement. Scrolling right through the results,<br />

1 If you right-click in the query window of SSMS, you can select Results To | Results to Text, which offers a more conventional view<br />

of the text execution plan.<br />

118

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!