Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

ALTER INDEX REBUILD clears sys.dm_db_index_usage_stats

$
0
0

Question:I’m experiencing some strange behaviour with response from the SQL Server DMV sys.dm_db_index_usage_stats. I understand the sys.dm_db_index_usage_stats are refreshed every time there is a SQL Server restart. This is documented behaviour , which I build in to my understanding of how to interpret these statistics

The strange behaviour is when I execute a ALTER INDEX REBUILD and then check the sys.dm_db_index_usage_stats , the usage stats for the index disappear.

I’m using SQL Server 2012 Enterprise SP2

Answer:It sounds like you’re experiencing a bug which appeared in SQL Server 2012 and was fixed in SQL Server 2012 Service Pack 3 + CU3.

Download the latest service pack and use these instructions How to Install SQL Server service pack silently (SQL Server DBA)

The bug is when a ALTER INDEX myIndex ON myTable REBUILD is executed, it deletes the usage stats for that index. It deletes them without a SQL Server restart.

This problem only relates to an INDEX rebuild.

This will have an impact on how you think about analysing index usage stats straight after an index maintenance plan. In the index maintenance phase the program will rebuild indexes. For this version of SQL Server , the index usage stats will flatten to 0.

In case you thought you were going crazy , you’re not!But I’d recommend you apply the relevant Service Pack and cumulative update.

SQL Script - How to get the table size, index size and last user update

Calculate the Size of Index (SQL Server DBA)

Missing Indexes. Equality and Inequality on sys.dm_db_missing_index_details

Author: Jack Vamvas ( http://www.sqlserver-dba.com )

Viewing all articles
Browse latest Browse all 3160

Trending Articles