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

<strong>Plans</strong> for Basic Queries<br />

Chapter 2 described how to read graphical execution plans, building your understanding<br />

of what operators do and how the data flows from one operator to the next. Learning<br />

how to read graphical execution plans is not wasted time, because what you learned<br />

there also applies to reading text and XML execution plans. While these plans don't have<br />

icons and Property sheets, they consist of the exact same operators and properties; so, by<br />

learning how to read graphical execution plans, you also learn how to read text and XML<br />

execution plans.<br />

In early versions of <strong>SQL</strong> <strong>Server</strong>, only text-based execution plans were available and many<br />

people found them hard to read, especially when dealing with complex plans. Microsoft<br />

eventually relented and introduced graphical execution plans in <strong>SQL</strong> <strong>Server</strong> 7, in addition<br />

to offering text execution plans. I find graphical execution plans much easier to read than<br />

text plans, and I guess I'm not the only database professional who feels this way, as text<br />

execution plans are on the <strong>SQL</strong> <strong>Server</strong> deprecation list and will eventually go away.<br />

In <strong>SQL</strong> <strong>Server</strong> 2005, Microsoft modified the internal structure of execution plans. Instead<br />

of the proprietary binary format that they were formerly, now all graphical plans are<br />

actually XML underneath. We can access the XML in all these plans directly. Like textbased<br />

plans, XML plans can be difficult to read and analyze if you look straight at the<br />

raw XML code. So why did Microsoft decide to use XML for execution plans if they are<br />

difficult to read?There are several reasons for the change. Essentially, XML is a common<br />

file format that we can use programmatically, unlike text-based execution plans. This<br />

means you can use XQuery to access data within XML plans. XML plans also provide<br />

a much richer environment to store more execution plan details than ever before. In<br />

addition, XML plans are stored in a portable format that makes them easy to share with<br />

others. For example, I can send an XML plan to a fellow DBA, and she can use SSMS to<br />

graphically display and analyze it or run queries directly against it. Text-based plans, on<br />

the other hand, don't offer any of these benefits.<br />

116

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

Saved successfully!

Ooh no, something went wrong!