SQL Server Performance Tuning

Improve Your SQL Server Performance Enabling Data Compression

Updated
3 min read
Written by
Mark Varnas

What is the data compression feature in SQL Server?

It is a feature introduced in SQL Server 2008 Enterprise Edition.

Later, Microsoft added to Standard Edition of SQL Server 2016 SP1 and higher.

Data compression can improve your SQL Server performance, reducing I/O.

It support tables, clustered index, non-clustered index.

Compression requires a bit more CPU, but it is not a problem when the majority of systems are IO-bound, not CPU-bound, so the trade-off is worth it.

SQL gains performance in multiple areas

  • Data take less space in memory;
  • Backups and restores are smaller and, therefore, faster;
  • Reduces load on storage;
  • Helps always-on/mirroring/log shipping/replication “go” faster;

How to identify tables and indexes to use data compression?

  1. Start with the objects from the query below (or you can start with the largest tables/indexes).
SELECT SCHEMA_NAME(o.Schema_ID) AS [Schema Name]
	,OBJECT_NAME(p.[object_id]) AS [Object Name]
	,p.index_id
	,CAST(COUNT(*) / 128.0 AS DECIMAL(10, 2)) AS [Buffer size(MB)]
	,COUNT(*) AS [BufferCount]
	,p.[Rows] AS [Row Count]
	,p.data_compression_desc AS [Compression Type]
FROM sys.allocation_units AS a WITH (NOLOCK)
INNER JOIN sys.dm_os_buffer_descriptors AS b WITH (NOLOCK) ON a.allocation_unit_id = b.allocation_unit_id
INNER JOIN sys.partitions AS p WITH (NOLOCK) ON a.container_id = p.hobt_id
INNER JOIN sys.objects AS o WITH (NOLOCK) ON p.object_id = o.object_id
WHERE b.database_id = CONVERT(INT, DB_ID())
	AND p.[object_id] > 100
	AND OBJECT_NAME(p.[object_id]) NOT LIKE N'plan_%'
	AND OBJECT_NAME(p.[object_id]) NOT LIKE N'sys%'
	AND OBJECT_NAME(p.[object_id]) NOT LIKE N'xml_index_nodes%'
GROUP BY o.Schema_ID
	,p.[object_id]
	,p.index_id
	,p.data_compression_desc
	,p.[Rows]
ORDER BY [BufferCount] DESC
OPTION (RECOMPILE)
  1. Determine if page or row-level compression is best for each object.
  2. Compress

More information

Article by
Mark Varnas
Founder | CEO | SQL Veteran
Hey, I'm Mark, one of the guys behind Red9. I make a living performance tuning SQL Servers and making them more stable.

Managed SQL Server services, consulting, and emergency support from expert DBAs to improve performance, predictability, and cost.

Get started with Red9 today.

Contact us

Discover More

SQL Server Health Check SQL Server Migrations & Upgrades SQL Server Performance Tuning SQL Server Security SQL Server Tips

Discover what clients are saying about Red9

Red9 has incredible expertise both in SQL migration and performance tuning.

The biggest benefit has been performance gains and tuning associated with migrating to AWS and a newer version of SQL Server with Always On clustering. Red9 was integral to this process. The deep knowledge of MSSQL and combined experience of Red9 have been a huge asset during a difficult migration. Red9 found inefficient indexes and performance bottlenecks that improved latency by over 400%.

Rich Staats 5 stars
Rich Staats
Cloud Engineer
MetalToad

Always willing to go an extra mile

Working with Red9 DBAs has been a pleasure. They are great team players and have an expert knowledge of SQL Server database administration. And are always willing to go the extra mile to get the project done.
5 stars
Evelyn A.
Sr. Database Administrator

Boosts server health and efficiency for enhanced customer satisfaction

Since adding Red9 to the reporting and DataWarehousing team, Red9 has done a good job coming up to speed on our environments and helping ensure we continue to meet our customer's needs. Red9 has taken ownership of our servers ensuring they remain healthy by monitoring and tuning inefficient queries.
5 stars
Andrew F.
Datawarehousing Manager
See more testimonials