SQL Performance slow when accessing most recent records
I have a MSSQL2005 database that has records dating back to 2004, there are currently just under 1,000,000 records in one particular table.
Thing is, if I run a report comparing 2009 data against 2010 data, 2008 against 2009, 2009 against 2009 or any combination of years before this year then results are returned in 1-5 seconds.
If however I run a report that includes 2011 data then the report takes ~6 minutes.
I've checked the data and it looks similar to previous years and is cross-referenced against the same data used in all of the reports.
It's as if the database has exceeded 开发者_开发百科some limit; that data for this year has become fragmented and therefore harder to access. I'm not saying this is the case but it may be for all I know.
Anyone have any suggestions?
Shaun.
Update:
Since posting the question I found DBCC DBREINDEX table_name which seems to have done the trick.What do the execution plans look like? If different you might need to manually update statistics on the table as the newly inserted rows are likely to be disproportionately unrepresented in the statistics and it might thus choose a sub optimal plan.
See this blog post for an explanation of this issue Statistics, row estimations and the ascending date column
Additionally check that your 2011 query isn't encountering blocking due to concurrent inserts or updates that do not affect queries against historic data.
精彩评论