What is the difference between OFFLINE and ONLINE index rebuild in SQL Server?

前端 未结 3 768
遥遥无期
遥遥无期 2021-02-01 12:30

When rebuilding an index, there is an option for ONLINE=OFF and ONLINE=ON. I know that when ONLINE mode is on, it makes a copy of the index, switches new queries to utilizing it

3条回答
  •  被撕碎了的回忆
    2021-02-01 12:58

    Online index rebuilds are less intrusive when it comes to locking tables. Offline rebuilds cause heavy locking of tables which can cause significant blocking issues for things that are trying to access the database while the rebuild takes place.

    "Table locks are applied for the duration of the index operation [during an offline rebuild]. An offline index operation that creates, rebuilds, or drops a clustered, spatial, or XML index, or rebuilds or drops a nonclustered index, acquires a Schema modification (Sch-M) lock on the table. This prevents all user access to the underlying table for the duration of the operation. An offline index operation that creates a nonclustered index acquires a Shared (S) lock on the table. This prevents updates to the underlying table but allows read operations, such as SELECT statements."

    http://msdn.microsoft.com/en-us/library/ms188388(v=sql.110).aspx

    Additionally online index rebuilds are a enterprise (or developer) version only feature.

提交回复
热议问题