Sql-Server
RCSI 和索引維護
我有一個啟用 RCSI 的數據庫,只要我記得,我就一直在線上重建我的索引(SQL 2014 Enterprise)。我的理解是,如果我們要離線重建索引,我們會失去額外的 14 個字節。但是,只要我們繼續線上重建或重組,我們將保留每行 14 個字節。那是對的嗎?
但是,只要我們繼續線上重建或重組,我們將保留每行 14 個字節。那是對的嗎?
這是真的。
REBUILD WITH (ONLINE = ON)
並將REORGANIZE
保留 14 個字節原樣。一個正常的REBUILD
會清除它。如果您禁用 RCSI,則 14 字節版本標記將被您提到的三個操作中的任何一個清除:
REBUILD
REBUILD WITH (ONLINE = ON)
REORGANIZE
為了您將來的參考,自己測試一下並不難。只需創建一個數據庫和表,然後嘗試不同的操作,每次檢查行大小。
USE [master]; GO CREATE DATABASE AreSeaEssEye; GO USE [AreSeaEssEye]; GO CREATE TABLE dbo.Foo (c1 INT NOT NULL); INSERT INTO dbo.Foo (c1) VALUES (1); ALTER TABLE dbo.Foo ADD CONSTRAINT PK_Foo PRIMARY KEY (c1); -- Baseline (11) select max_record_size_in_bytes from sys.dm_db_index_physical_stats (db_id('AreSeaEssEye'), object_id('AreSeaEssEye.dbo.Foo'), null, null, 'DETAILED'); ALTER DATABASE AreSeaEssEye SET ALLOW_SNAPSHOT_ISOLATION ON; UPDATE dbo.Foo SET c1 = 2; -- After enabling RCSI and updating (25) select max_record_size_in_bytes from sys.dm_db_index_physical_stats (db_id('AreSeaEssEye'), object_id('AreSeaEssEye.dbo.Foo'), null, null, 'DETAILED'); ALTER INDEX PK_Foo ON dbo.Foo REBUILD WITH (ONLINE = ON); -- After online rebuild (still 25) select max_record_size_in_bytes from sys.dm_db_index_physical_stats (db_id('AreSeaEssEye'), object_id('AreSeaEssEye.dbo.Foo'), null, null, 'DETAILED'); ALTER INDEX PK_Foo ON dbo.Foo REORGANIZE; -- After reorg (still 25) select max_record_size_in_bytes from sys.dm_db_index_physical_stats (db_id('AreSeaEssEye'), object_id('AreSeaEssEye.dbo.Foo'), null, null, 'DETAILED'); ALTER INDEX PK_Foo ON dbo.Foo REBUILD; -- After normal rebuild (back to 11) select max_record_size_in_bytes from sys.dm_db_index_physical_stats (db_id('AreSeaEssEye'), object_id('AreSeaEssEye.dbo.Foo'), null, null, 'DETAILED');
結果呢?正如預期的那樣: