开发者

When and why do I reindex a MSDE database

开发者 https://www.devze.com 2022-12-10 12:46 出处:网络
I understand that indexes should get updated automatically but when that does not happen we need to reindex.

I understand that indexes should get updated automatically but when that does not happen we need to reindex.

My question is (1) Why this automatic udate f开发者_如何学编程ails or why an index become bad? (2) How do I prgramatically know which table/index needs re-indexing at a point of time?


Indexes' statistics may be updated automatically. I do not believe that the indexes themselves would be rebuilt automatically when needed (although there may be some administrative feature that allows such a thing to take place).

Indexes associated with tables which receive a lot of changes (new rows, updated rows and deleted rows) may have their indexes that become fragmented, and less efficient. Rebuilding the index then "repacks" the index in a contiguous section of storage space, a bit akin to the way defragmentation of the file system makes file access faster...

Furthermore the Indexes (on several DBMS) have a FILL_FACTOR parameter, which determine how much extra space should be left in each node for growth. For example if you expect a given table to grow by 20% next year, by declaring the fill factor around 80%, the amount of fragmentation of the index should be minimal during the first year (there may be some if these 20% of growth are not evenly distributed,..)

In SQL Server, It is possible to query properties of the index that indicate its level of fragmentation, and hence it possible need for maintenance. This can be done by way of the interactive management console. It is also possible to do this programatically, by way of sys.dm_db_index_physical_stats in MSSQL 2005 and above (maybe even older versions?)

0

精彩评论

暂无评论...
验证码 换一张
取 消