Question

As I know, while online index is rebuilding, SQL Server virtually creates an index and then at the end it swaps the existing old index with the new created one and then finally drops the old index.

I would like to know if these operation are the same for offline index rebuild. Will SQL Server create virtually an index and then swap it with the existing one?

Was it helpful?

Solution

Consider what Paul Randal says in his post on Search Engine Q&A #19: Misconceptions around index rebuilds (allocation, BULK_LOGGED mode, locking):

Index rebuild (whether online or offline, and at least as far back as 7.0) will create a new copy of the index before dropping the old copy.

He reiterates that point in SQLskills SQL101: REBUILD vs. REORGANIZE:

Rebuilding an index requires building a new index before dropping the old index...

Finally, the documentation also discusses this on the page Reorganize and rebuild indexes:

Rebuilding an index drops and re-creates the index.

So the answer to your question is yes, a new index is created and the old one is dropped when rebuilding an index offline (although it will generally require less disk space than the online version of the operation).

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top