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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 8.13<br />

Chapter 8: Advanced Topics<br />

If we change the value to 288, we see an Index Seek with a Bookmark Lookup.<br />

Figure 8.14<br />

This is much faster than the Clustered Index Scan. If the execution plan for the<br />

procedure takes the first value for its plan, then the later values still use the Clustered<br />

Index Scan. While we could simply add a plan guide that uses the OPTIMIZE FOR hint,<br />

we're going to try USE PLAN instead.<br />

First, we need to create an XML plan that behaves the way we want. We do this by taking<br />

the SELECT criteria out of the stored procedure and modifying it to behave the correct<br />

way. This results in the correct plan. In order to capture this plan, we'll wrap it with<br />

STATISTICS XML, which will generate an actual execution plan in XML.<br />

319

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

Saved successfully!

Ooh no, something went wrong!