If you need to add, remove, or replace hints from ad-hoc queries where you can’t change the code, plan guides can help. See a demo of removing a query hint from parameterized TSQL run from an application, and get tips on how to make your plan guides work in SQL Server.
The code from the demo is here. Links for more info are below the video. Have fun!
Option 1: Listen to the 30 minute audio podcast episode (or download it!)
Option 2: Watch the YouTube video
This is the exact same content as in the audio podcast, but with visuals of the slides and demos.
The video shows creating a plan guide with sp_create_plan_guide to remove a query hint, but you can use plan guides to do much more!
- You can add or remove table hints (such as an index hint or a FORCESCAN hint), using slightly different syntax with sp_create_plan_guide. See examples in Books Online here.
- You can force parameterization of specific queries using sp_create_plan_guide to create a ‘TEMPLATE’ type plan guide. See example syntax on this type of plan guide here.
- You can “freeze” an execution plan so that it is always used for the query. For this one, you use the procedure sp_create_plan_guide_from_handle. See code on how to do this here.