liveBook · Manning

Compression

As explained in 100 SQL Server Mistakes and How to Avoid Them

Data compression encodes stored database data in a more compact representation to reduce storage and I/O requirements.

Compression is not automatically a performance penalty. For I/O-bound workloads with spare processor capacity, row or page compression can reduce pages read and relieve pressure on the I/O subsystem. section 10.9

Avoid the mistake of leaving large tables uncompressed when their workload fits these conditions:

  • Check whether the workload is I/O bound and has spare processor capacity; compression exchanges processor cycles for fewer pages read. section 10.9
  • Measure before changing the table. Compression savings depend on the data stored, so estimate row and page options before implementation. section 10.14
  • Verify the result through I/O statistics or metadata page counts rather than assuming that an ALTER TABLE operation delivered useful savings. section 10.9

ImpressionArchive

An uncompressed ImpressionArchive table required 46,982 pages. Rebuilding it with row compression reduced storage to 33,687 pages, an approximate 28% reduction. Row compression uses variable-length decimal storage: a BIGINT value of 10 can use one byte, 50,000 can use four bytes, and NULL uses no space. section 10.9

Listing 10.17 Implementing row compression
ALTER TABLE ImpressionsArchive
   REBUILD WITH (DATA_COMPRESSION = ROW) ;

Apply row compression with ALTER TABLE ... REBUILD and DATA_COMPRESSION = ROW. section 10.9

Listing 10.20 Estimating table size with compression
EXEC sp_estimate_data_compression_savings 
   @schema_name = 'dbo', 
   @object_name = 'ImpressionsArchive', 
   @index_id = 1, 
   @partition_number = NULL, 
   @data_compression = 'none' ;

Estimate compressed table size with sp_estimate_data_compression_savings before implementation. section 10.9

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains row-compression storage internals, demonstrates page reductions, and names page compression without detailing its internal structure.
Examples
Uses ImpressionArchive, page counts, ALTER TABLE rebuilds, metadata queries, and compression-savings estimation.
What it assumes
Assumes familiarity with large tables, pages, clustered indexes, I/O, and ALTER TABLE, while explaining row-compression storage behavior.
What you can do after
Operate/configure SQL Server compression, estimate savings, implement row or page compression, and verify resulting page usage.
How it connects
Connects compression with I/O-bound workloads, query performance, partitioning, clustered indexes, and processor capacity.

Also explained in

Compare how 11 books explain compression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.