SQL Performance slow when accessing most recent records

前提是你 提交于 2019-12-17 20:51:57

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6109246/sql-performance-slow-when-accessing-most-recent-records

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!