How to Estimate Space Saved by Data Compression in SQL Server? – Interview Question of the Week #167

Question: How can I estimate the space savings from ROW or PAGE compression before changing a SQL Server table?

A bookbinder's press compares a thick paper stack with a compact one

Answer: I remember being asked this almost every day when disk space was expensive. Storage may be cheaper now, but a smaller table can still affect I/O, memory use, CPU and maintenance time. An estimate is more useful than choosing a compression setting by habit.

SQL Server provides sys.sp_estimate_data_compression_savings. Here it is for the Sales.InvoiceLines table in WideWorldImporters, once for ROW and once for PAGE:

USE WideWorldImporters;
EXEC sys.sp_estimate_data_compression_savings
    @schema_name = N'Sales',
    @object_name = N'InvoiceLines',
    @index_id = NULL,
    @partition_number = NULL,
    @data_compression = N'ROW';

EXEC sys.sp_estimate_data_compression_savings
    @schema_name = N'Sales',
    @object_name = N'InvoiceLines',
    @index_id = NULL,
    @partition_number = NULL,
    @data_compression = N'PAGE';

Compare size_with_current_compression_setting(KB) with size_with_requested_compression_setting(KB) in each result. The procedure samples data and builds an equivalent sample in tempdb; it estimates storage, it doesn’t apply compression. An estimate may show little saving or even growth. Run it when the required permissions and tempdb capacity are available, and test CPU and query behavior before a production rebuild.

Index IDCurrent size (KB)Estimated ROW size (KB)Estimated PAGE size (KB)
140,02420,80014,384
23,1762,5682,424
34,9603,6883,360
43,2082,3122,008
61,6886,4964,544
One SQL Server 2025 test of Sales.InvoiceLines in WideWorldImporters. These are that run’s estimates in KB, not guaranteed savings for another database.

Notice index 6: both requested settings estimate a larger size than its current format. That’s a reason to inspect the existing index and compression before changing it. The procedure didn’t rebuild these indexes; it produced estimates from samples.

The procedure also accepts NONE to estimate an uncompressed state, and newer versions support other compression types. My answer to the interview question is simple: measure the specific table and indexes first, then decide whether the storage estimate and the workload justify the change. What surprised you most when you compared ROW and PAGE estimates?

Data compression: Estimate before you rebuild

Compression is not free space, it is a trade of CPU for pages, so estimate before you rebuild.

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.

Compression, SQL Scripts, SQL Server, SQL Stored Procedure
Previous Post
Which is Better for Performance – SELECT or SET? – Interview Question of the Week #166
Next Post
What is SQL Server Launchpad Service? – Interview Question of the Week #168

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.