Reputation: 2359
I have a moderately complex nested T-SQL query, which for the most part has good performance, except at the start of each of my 2-week pay periods (where there are fewer records to process!) the query bogs down orders of magnitude slower. Then at some point in the bi-weekly period, SQL Server (2008) determines the execution plan should change and everything is back to normal speeds. I have the execution plans for the "good" and "bad" scenarios, but I am a n00b in this area and I do not know how to interpret them. What is the next step for me here? Post the query? The execution plans? Read some articles/book?
Upvotes: 1
Views: 218
Reputation: 2359
I got some help over at answers.sqlperformance.com, and while UPDATE STATISTICS <table>
does help, it appears to be masking the real problem. I was using the constructs (SELECT COUNT(*) ...) = 0
and (SELECT * ...) IS NULL
when I should have been using NOT EXISTS (SELECT * ...)
. Changing these resulted in almost another order of magnitude improvement in all cases. It looks like the SQL Plan Optimizer is able to work much better in this case.
Upvotes: 1
Reputation: 6405
Try updating statistics on the tables in the query at the start of the 2 week period:
DBCC UPDATE STATISTICS table-name
there are some options, like WITH FULLSCAN you could experiment with as well. Take a look in the SQL Server docs.
Upvotes: 1