• SQL Pizza (4/19/2013)


    Oh man...if it wouldn't take me so long to obfuscate it. It's a normal query using cte to gather some values of 3 joined tables and the results get aggregated. I optimized the query over a long time playing around with different indexes and rewrote the query using different approaches. So the query is optimal with it's 300 ms. But sometimes the query takes 8000 ms allthough there's almost no load on the server. So I wanted to know if you got practical experiences with this behaviour?

    Yes but I have no context to see what MIGHT be the issue. Is this a stored proc? There is not much hope of helping figure it out without some details. 😉

    My two best guesses with no information is parameter sniffing (if it is a proc) or stale statistics.

    _______________________________________________________________

    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/