strange SQL server report performance problem related with update statistics

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 16:59:48

问题


I got a complex report using reporting service, the report connect to a SQl 2005 database, and calling a number of store procedure and functions. it works ok initially, but after a few months(data grows), it run into timeout error.

I created a few indexes to improve the performance, but the strange thing it that it works after the index was created, but throws out the same error the next day. Then I try to update the statistics on the database, it works again (the running time of the query improve 10 times). But again, it stop working the next day.

Now, the temp solution is that I run the update statistic every hour. But I can't find a reasonable explanation for this behaviour. the database is not very busy, there won't be lots of data being updated for one day. how can the update statistics make so much difference?


回答1:


I suspect you have parameter sniffing. Updating statistics merely forces all query plans to be discarded, so it appears to work for a time

CREATE PROC dbo.MyReport
    @SignatureParam varchar(10),
    ...
AS
...
DECLARE @MaskedParam varchar(10), ...
SELECT @MaskedParam = @SignatureParam, ...

SELECT...WHERE column = @MaskedParam AND ...
...
GO



回答2:


I've seen this problem when the indexes on the underlying tables need to be adjusted or the SQL needs work.

The rebuild index and the update statistics read the table into the cache, which improves performance. The next day the table has been flushed out of the cache and the performance problems return.

SQL Profiler is very useful in these situations to identify what changes from run to run.



来源:https://stackoverflow.com/questions/1592552/strange-sql-server-report-performance-problem-related-with-update-statistics

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