SqlShare.com Logo
 
Skip Navigation Links
Home
Video List
Events
Classes
About Us
Login / Register
Subscribe RSS Feed 

Confio Ignite

Solve Parameter Sniffing by Using A Plan Guide

Parameter sniffing is a process that occurs when executing a stored procedure for the first time that allows SQL Server to build an effective query plan. This video shows you how to limit the performance effects of parameter sniffing by utilizing plan guides (sp_create_plan_guide).

Duration:
4 mins 36 secs
Skill Level:
200
Rating:
4.11 out of 5
Publish Date:
November 06, 2008
Solve Parameter Sniffing by Using  A Plan Guide You must be logged in to view this video.  
Bookmark and Share
 
1=Poor, 3=Good, 5=Excellent

About the Author

Image of Plamen Ratchev
Plamen Ratchev has over two decades experience in the software architecture and development field. He has enjoyed building solutions for UNIX, DOS and Windows platforms, with main focus on SQL Server since version 4.21. Plamen is founder of Tangra, specializing in relational database applications analysis, implementation, and tuning. His particular interest is in design patterns, performance a...

References

There are no downloads or recommended reading links for this video

Comments
tavis on 4/10/2009
interesting.

Lonnie Meinke on 4/10/2009
I'm unfamiliar with plan guides and parameter sniffing....needed a little more background.

Don Weigend on 4/10/2009
Creating a plan guide seems like an option to possibly solve a performance problem without having to make a stored procedure change and go through change control to get it into production. It would be nice to explain some other uses ir reasons to use this feature. It seems that with more complex stored procedures using this feature could be hard to do. I get the idea from this video that you need to include all the SQL from the stored procedure that may have performace problems. This means there will be a lot of plan guides to manage. This could be problematic. However, this feature does make for another tool to help with keeping things running smoothly.

Holck on 4/10/2009
This was really interesting. I liked how the presenter gave some background, although for some novices it might have been helpful to define what a table scan is and what the query hint that was used here will do along with where to find more information on other query hints. I also wasn't sure if doing this would fix the problem once the SP had already been run, since I've never used query hints (I'm a developer not a DBA).

SUBRATA SARKAR on 4/10/2009
incomplete video

Edward Thompson on 4/11/2009
This could have been much better if the typing was done before hand so the concentration was focused on the topic points. Thank you for showing me this feature.

Plamen Ratchev on 4/13/2009
Don, one of the best uses for plan guides in my opinion is when dealing with third-party software. As a DBA or developer many times you have to solve a problem where the vendor does not allow you to change their code. In that case you can simply apply a plan guide and tune a query without changing code.

Plamen Ratchev on 4/13/2009
SUBRATA, there is a more complete explanation with more examples on my blog: http://pratchev.blogspot.com/2007/08/parameter-sniffing.html.

Prasanna Prabhu on 5/1/2009
Liked the video. One problem I see is, your demo was for simple use-case scenario. In this very video your SQL (within "GetCustomerOrders" as well as "sp_create_plan_guide") was a simple SELECT statement, but in real-life scenarion SQL code may not be as simple as it looks (or atleast there are multiple SQL statements within an SP). How do we handle that within "sp_create_plan_guide"? Do we cut-and-paste the code from User Defined SP to code within "sp_create_plan_guide"? That can be quite an risky proposition (code duplication). What solutiuons we have for those scenario

Plamen Ratchev on 5/2/2009
Prasanna, plan guides apply to a single query, so if your stored procedure has multiple queries you would have to create multiple plan guides (since a plan guide is used to apply a hint to a single query). But in general you should not have to apply hints to all queries in the stored procedure. See the article "How SQL Server Matches Plan Guides to Queries" on how the query text is matched in the plan guide: http://technet.microsoft.com/en-us/library/ms189296.aspx. Also, "Designing and Implementing Plan Guides": http://technet.microsoft.com/en-us/library/ms189854.aspx

4B47653576 on 5/17/2009
perhaps mention the cost of the recompile and plan guide.

Plamen Ratchev on 5/18/2009
The cost of the recompilation can be a small fraction of the total cost compared to the gains of solving parameter sniffing. However, a stored procedure that is executed very frequently can turn into a bottle neck because of recompilations. But in that case another approach (like OPTION OPTIMIZE FOR) can be used (which does not force recompile).

Ahmad Elayyan on 8/22/2009
good

4B47653576 on 9/1/2010
very good. would like to see mention of costs in diufferent options such recompiling or what other hints can be supplied. Can you use optimise for in the hint for example?

Plamen Ratchev on 9/2/2010
4B47653576, yes, you can use OPTION OPTIMIZE FOR in the hint.

Dietlev on 9/6/2011
I would prefer properly spoken english - it is important for foreigners

Travis on 9/6/2011
Wouldn't it be easier/cleaner to just create local variables in the SP?

revanth on 9/6/2011
nice

Steve Harris on 9/6/2011
why not just alter the procedure to add the option to recompile

Dean Dodson on 9/6/2011
Thank you for this topic, it was new to me.

jerry on 9/6/2011
it would be nice if you could understand the presenter.

James Moore on 9/6/2011
not clear why option(recompile) solves the problem?

shibu on 9/6/2011
Really good... will pay the attention more...

Mike on 9/6/2011
Option RECOMPILE course the procedure to be recompiled every time and slow down performance. Use internal variables to reassign parameters values

Dick Rosenberg on 9/6/2011
Really useful presentation!

John Langston on 9/6/2011
very useful.

Carlos B. Vasquez on 9/6/2011
I wasn't clear until now about the Parameter Sniffing, Thanks.

san on 9/6/2011
The select statement didnt match the tsql within the stored proc. hence, the plan guide would not work but its what shown in this video. not accurate at all.

san on 9/6/2011
sorry, my post is inaccurate. i mislook and thought the plan guide would not work, but it'll work.

lital on 9/7/2011
can you tell how to identify it? how can i tell that the query is not optimized?

DavidB on 9/7/2011
Showing the use of sp_create_plan_guide was great. The solution that was shared could have been better.

Thom Bolin on 9/7/2011
would like to have an example with/without the plan guide

Dave on 9/8/2011
Would have been nice to see an execution plan showing before and after of the sp_create_plan_guide.

Maurice Ivory on 2/16/2012
it was hard to pay attention to this one.



Must Be Logged In
 

How Do I Become a Video Author? |  Newsletter History

Copyright © Fourdeuce, Inc., 2005-2009. All Rights Reserved | Privacy Policy | Terms & Conditions