SQL Server: What is the difference between Index Rebuilding and Index Reorganizing?

前端 未结 7 1251
暗喜
暗喜 2021-02-05 05:37

What is the difference between Index Rebuilding and Index Reorganizing?

7条回答
  •  盖世英雄少女心
    2021-02-05 05:48

    REBUILD locks the table for the whole operation period (which may be hours and days if the table is large).

    REORGANIZE doesn't lock the table.

    Well. actually, it places some temporary locks on the pages it works with right now, but they are removed as soon as the operation is complete (which is fractions of second for any given lock).

    As @Andomar noted, there is an option to REBUILD an index online, which creates the new index, and when the operation is complete, just replaces the old index with the new one.

    This of course means you should have enough space to keep both the old and the new copy of the index.

    REBUILD is also a DML operation which changes the system tables, affects statistics, enables disabled indexes etc.

    REORGANIZE is a pure cleanup operation which leaves all system state as is.

提交回复
热议问题