High CPU usage (Because of bad execution plan)

  • 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

  • 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 Monday Morning DBA 
    There are two means of refuge from the miseries of life: music and cats. ~ Albert Schweitzer

  • 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

  • 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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply