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

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

What is the difference between Index Rebuilding and Index Reorganizing?

7条回答
  •  你的背包
    2021-02-05 06:05

    Think about how the index is implemented. It's generally some kind of tree, like a B+ Tree or B- Tree. The index itself is created by looking at the keys in the data, and building the tree so the table can be searched efficiently.

    When you reorganize the index, you go through the existing index, cleaning up blocks for deleted records etc. This could be done (and is in some databases) when you make a deletion, but that imposes some performance penalty. instead, you do it separately in order to do it more or less batch mode.

    When you rebuild the index, you delete the existing tree and read all the records, building a new tree directly from the data. That gives you a new, and hopefully optimized, tree that may be better than the results of reorganizing the table; it also lets you regenerate the tree if it somehow has been corrupted.

提交回复
热议问题