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 />

To most people, an XML plan is simply a common file format in which to store a graphical<br />

execution plan, so that they can share it with other DBAs and developers.<br />

I would imagine that very few people would prefer to read execution plans in the raw<br />

XML format. Having said that, there is one over-riding reason why you will absolutely<br />

want to use the raw XML data as a tool in your toolbox, and that is programmability. You<br />

can run XQuery T-<strong>SQL</strong> queries against XML files and XML plans. In effect, this gives us a<br />

direct means of querying the plans in the plan cache. This means we can display specific<br />

details of a plan and, by performing a search on specific terms, such as "Index Scan," we<br />

can track down specific, potentially problematic, aspects of a query. We'll see an example<br />

of this a little later.<br />

XML plans can also be used in plan forcing, where we essentially dictate to the query<br />

optimizer that it should use only a specified plan to execute the query. We'll cover this<br />

topic in detail in Chapter 8, but it's worth noting here that, contrary to what you might<br />

hear, plan forcing does not bypass the optimization process.<br />

In the following section, we take a brief look at the structure of XML as it exists behind<br />

graphical plans and in the plan cache.<br />

An estimated XML plan<br />

This section will show the information available to you in an XML plan. Just to get a<br />

sense of the XML structure, you'll follow through this example and "read" the XML in<br />

the same way as you have done previously for graphical and text plans. However, this<br />

example is not representative of how you're really going to use XML execution plans in<br />

your day-to-day work. You won't generally be browsing through the raw XML data in an<br />

attempt to find information.<br />

127

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

Saved successfully!

Ooh no, something went wrong!