DB Maintenance - SPROCs running slow

  • Good day,

    Everytime I run my maintenance (daily at night), my SPROCs start to time out. If I run my SPROCs directly in Management Studio, they run fine since it creates a new execution plan everytime it runs (I assume). When I run it through my application (ADO.NET/C#), it times out.... and the only way to fix this is to go and recompile the stored procedure manually, then everything runs fine.

    Is there something I am doing bad with my maintenance?

    The following are my maintenance steps that I run daily;

    1) DBCC CHECKDB(N'DBNAME') WITH NO_INFOMSGS

    2) Then it goes through all index (Reorganize)

    ALTER INDEX [PK_Allergies] ON [dbo].[Allergies] REORGANIZE WITH ( LOB_COMPACTION = ON )

    3) Then it updates STATISTICS on all Tables with FULLSCAN

    Is there something I'm not doing right? Any suggestions?

    Regards,

  • sgrimard (4/29/2015)


    Good day,

    Everytime I run my maintenance (daily at night), my SPROCs start to time out. If I run my SPROCs directly in Management Studio, they run fine since it creates a new execution plan everytime it runs (I assume). When I run it through my application (ADO.NET/C#), it times out.... and the only way to fix this is to go and recompile the stored procedure manually, then everything runs fine.

    Is there something I am doing bad with my maintenance?

    The following are my maintenance steps that I run daily;

    1) DBCC CHECKDB(N'DBNAME') WITH NO_INFOMSGS

    2) Then it goes through all index (Reorganize)

    ALTER INDEX [PK_Allergies] ON [dbo].[Allergies] REORGANIZE WITH ( LOB_COMPACTION = ON )

    3) Then it updates STATISTICS on all Tables with FULLSCAN

    Is there something I'm not doing right? Any suggestions?

    Regards,

    Sounds like parameter sniffing. http://sqlinthewild.co.za/index.php/2007/11/27/parameter-sniffing/[/url]

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • +1 to what Sean said. That would be my guess.

  • Thanks guys, I've implemented the fix and will be pushing it out tonight... hopefully it will resolve this issue.

    I appreciate the quick feedback!

  • Any chance you could share what you changed? Might help someone else.

    Code would be nice if you can show it.

  • No problem, I cannot post my exact code for legal purposes but I will draft up an example for all the others.

    Technically, the link that you've provided suggested using localVariables to resolve this issue.

    Let's say my SPROC was the following before I made the changes;

    CREATE Procedure [dbo].[Procedures]

    (

    @PersonID int

    )

    As

    SELECT FirstName, LastName From Person where PersonID = @PersonID

    The changes I made is to declare a local variable in the stored procedure, the code would look like;

    CREATE Procedure [dbo].[Procedures]

    (

    @PersonID int

    )

    As

    DECLARE @LocalPersonID int = @PersonID

    SELECT FirstName, LastName From Person where PersonID = @LocalPersonID

    This is what the post suggested and its explanation can be found in the link posted previously in this thread.

    I will update this thread in a week to confirm that this fixed the issue.

    Thanks again for all the help!

  • Thanks

Viewing 7 posts - 1 through 6 (of 6 total)

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