SQL SERVER – Rebuilding Index with Compression

To rebuild an Index with Compression, I target its own settings and partitions. Customer ROW and PAGE results need separate evaluation.

Matching cloth panels preserve their motif under two different folding methods.

SELECT i.name,p.partition_number,p.data_compression_desc
FROM sys.indexes i JOIN sys.partitions p ON p.object_id=i.object_id AND p.index_id=i.index_id
WHERE i.object_id=OBJECT_ID(N'Production.TransactionHistory')
ORDER BY i.index_id,p.partition_number;
-- Original table/heap or clustered-data rebuild shapes:
-- ALTER TABLE Production.TransactionHistory REBUILD WITH (DATA_COMPRESSION=ROW);
-- ALTER TABLE Production.TransactionHistory REBUILD WITH (DATA_COMPRESSION=PAGE);
-- An individually selected nonclustered index has its own setting:
-- ALTER INDEX [YourIndex] ON Production.TransactionHistory REBUILD
--     WITH (DATA_COMPRESSION=PAGE);

My old ALTER TABLE … REBUILD examples targeted table data. They did not set every nonclustered index compression option. Use ALTER INDEX for the intended named index. Inspect relevant partitions first.

ROW and PAGE can save space and reads while costing CPU. Eligibility depends on engine, edition and object. Rebuilds consume resources and log space. Plan locks and supported online behavior.

Estimate savings and compare representative reads, writes, CPU and duration on a copy. Preserve earlier settings and rollback definitions. Retaining the current configuration is valid when measurements don’t support change.

Reference: Index rebuild and independent compression settings.

Related reading

A table rebuild is not automatic compression of every nonclustered index, it is work on the targeted storage structure.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Index, SQL Scripts, SQL Server
Previous Post
Trigger Blocks Index Maintenance: How to Let Rebuilds Pass
Next Post
Aggregate Pushdown: Letting the Columnstore Scan Do the Summing

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.