|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:30 PM
Points: 174,
Visits: 661
|
|
Hi everyone,
We have a server, which has SQL SERVER 2008 R2,periodically we face with high CPU usage(100%) on this server.We found out that the high CPU usage is related to a bad execution plan for a stored procedure.After recompiling the Stored Procedure,The CPU usage come back to normal.Is there any way to prevent cashing the bad execution plan ?
Thanks
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Yesterday @ 11:10 AM
Points: 305,
Visits: 311
|
|
If the SP uses parameters in the WHERE or JOIN clauses, you might investigate the possibility that parameter sniffing caused a bad plan to be cached. There are many excellent articles on parameter sniffing available on SSC, just do a search of articles and blogs.
Roland Alexander The Developing World
There are two means of refuge from the miseries of life: music and cats. ~ Albert Schweitzer
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Yesterday @ 7:35 AM
Points: 408,
Visits: 1,666
|
|
As stated above, it could be parameter sniffing. If you have identified what procedure runs that cause the sniffing capture that parameter in particular that causes this.
Now, don't put the recompile option for the procedure as a solution as that will be costly in the long run. Use other methods like declaring a local variable and copying the procedure parameter to it.
Also, if you would like some experts to look into your code to make it more elegant, please post the DDL and execution plans.
Thanks Chandan
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Today @ 1:30 AM
Points: 803,
Visits: 2,124
|
|
If it is a paramater sniffing option and you are using SQL2008 you can use the Query Hint OPTION(RECOMPILE) on the offending SELECT statement, which should solve the issue and give you and indication if this is the case.
As the previous poster suggested try to avoid using WITH RECOMPILE on functions an SP's as that can cause more problems.
_________________________________________________________________________ SSC Guide to Posting and Best Practices
|
|
|
|