Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Update SQL Server Statistics

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Update SQL Server Statistics

After statistics are invalidated:


 If auto-update-stats is enabled, the first plan that compiles and sees the invalid stats will update them there and
then.
 If auto-update-stats-async is enabled, the first plan that compiles and see the invalid stats will use the invalid stats
to compile and will cause an entry to be put on a task queue for a background task to update the stats.

If the table has no rows, statistics is updated when there is a single change in table.
Permanent table If the number of rows in a table is less than 500, statistics is updated for every 500 changes in table.
If the number of rows in table is more than 500, statistics is updated for every 500+20% of rows changes in table.
If the table has no rows, statistics is updated when there is a single change in table.
If the number of rows in table is less than 6, statistics is updated for every 6 changes in table.
Temporary table
If the number of rows in table is less than 500, statistics is updated for every 500 changes in table.
If the number of rows in table is more than 500, statistics is updated for every 500+20% of rows changes in table.
Table variable There is no statistics for Table Variables.

Exactly how often you should be updating statistics depends greatly on how much data modification your
indexes and data is receiving.

If there is very little modification (INSERT, UPDATE, DELETE) to the data, then you could have a more infrequent
schedule for the update statistics job.

One way to find out if your statistics are stale is to look at the execution plans and if you estimated rows greatly differ
from your actual rows returned then that is a good indication that the interval needs to be upped.

Synchronous (defaulted as AUTO_UPDATE_STATISTICS =TRUE)


開啟了「自動更新統計資料」後,在每次查詢時,都會檢查是不是要更新到最新的統計資料,所以如果查詢
的資料是很大的 Table,這時它發現統計資料不是最新的,就先去更新統計資料後才會執行使用者所下的
Query。

Auto Update Statistics Asynchronously (AUTO_UPDATE_STATISTICS_ASYNC =TRUE)


如果怕這種情況的發生,這時可以再將「自動非同步更新統計資料」以後才有的屬性設成 ON,它就不會卡
在 Query 之前先更新統計資料,而是以非同步的方式來更新。

如果啟用了「自動非同步更新統計資料」後,還是會影響日常的系統操作的話,就只好不要啟用「自動更新
統計資料」
,而在離峰時間,設定排程去「更新統計資料」

You might also like