Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

High CPU usage (Because of bad execution plan) Expand / Collapse
Author
Message
Posted Friday, October 5, 2012 12:28 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 29, 2014 5:46 PM
Points: 182, Visits: 737
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
Post #1369257
Posted Friday, October 5, 2012 12:36 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:09 PM
Points: 437, Visits: 334
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
Post #1369261
Posted Monday, October 8, 2012 1:31 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, September 30, 2014 11:40 PM
Points: 466, Visits: 1,923
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
Post #1369643
Posted Monday, October 8, 2012 3:17 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, October 3, 2014 9:25 AM
Points: 895, Visits: 2,432
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
Post #1369681
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse