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.

Chapter 8: Advanced Topics<br />

Aside from the procedure to create plan guides, a second one, sp_control_plan_<br />

guide, allows you to drop, disable, or enable a specific plan guide; or drop, disable, or<br />

enable all plan guides in the database.<br />

Simply run execute the sp_control_plan_guide procedure, changing the @<br />

operation parameter appropriately.<br />

EXEC sp_control_plan_guide @operation = N'DROP',<br />

@name = N'MyFourthPlanGuide'<br />

Listing 8.19<br />

Plan forcing<br />

The USE PLAN query hint, introduced in <strong>SQL</strong> <strong>Server</strong> 2005, allows you to come as close<br />

as you can to gaining total control over a query execution plan. This hint allows you to<br />

take an execution plan, captured as XML, and store it "on the side," for example, inside a<br />

plan guide, and then to use that plan on the query from that point forward. This doesn't<br />

stop the optimizer from doing its job. You'll still get full optimization depending on the<br />

query, but then whatever plan the optimizer produces is not used. Instead, it uses the<br />

plan you're "forcing."<br />

You cannot force a plan on:<br />

• INSERT, UPDATE or DELETE queries<br />

• queries that use cursors other than static and fast_forward<br />

• distributed queries and full text queries.<br />

Forcing a plan, just like all the other possible query hints, can result in poor performance.<br />

Proper testing and due diligence must be observed prior to applying USE PLAN.<br />

317

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

Saved successfully!

Ooh no, something went wrong!