SQL SERVER - Script to Estimate Compression - SQL Authority with Pinal Dave
source link: https://blog.sqlauthority.com/2021/12/15/sql-server-script-to-estimate-compression/?utm_campaign=sql-server-script-to-estimate-compression
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Today we are going to see something very simple thing which can make a huge difference in performance. Recently I had implemented Data Compression at my client Comprehensive Database Performance Health Check. Let us discuss how we can estimate compression in SQL Server.
There are two different kinds of compressions in SQL Server that are widely popular 1) Page Compression 2) Row Compression.
Two Kind of Compressions
If you have data that is read more and updated less for that table, you can go for Page Compression. If your tables are updated very frequently it is recommended that you go with Row Compression. In general, I have seen page compression more effective than row compression but again, this can vary based on how your data is and how your system is set up.
Data Compression – Yes or No?
The biggest question I often receive is that should opt for compression. Well, the answer is pretty straightforward. If you need to save space, you can go ahead with data and index compression. Compressed table and index take more CPU cycles than non-compressed data to write to disk. This means, if you have a CPU pressure, the compression will further degrade the performance.
Estimate Compression
You can easily estimate compression for your data table or index using the following script.
Page Compression Estimation
EXEC
sp_estimate_data_compression_savings
@schema_name =
'Production'
,
@object_name =
'WorkOrder'
,
@index_id =
NULL
,
@partition_number =
NULL
,
@data_compression =
'PAGE'
;
Row Compression Estimation
EXEC
sp_estimate_data_compression_savings
@schema_name =
'Production'
,
@object_name =
'WorkOrder'
,
@index_id =
NULL
,
@partition_number =
NULL
,
@data_compression =
'ROW'
;
Once you check your estimation and if you do not have a CPU pressure issue, you can easily enable compression by running the following script.
Enable Compression
Enable Page Compression
ALTER
TABLE
Production.WorkOrder REBUILD PARTITION =
ALL
WITH
(DATA_COMPRESSION = PAGE);
GO
Enable Row Compression
ALTER
TABLE
Production.WorkOrder REBUILD PARTITION =
ALL
WITH
(DATA_COMPRESSION = ROW);
GO
Disable Data Compression
ALTER
TABLE
Production.WorkOrder REBUILD PARTITION =
ALL
WITH
(DATA_COMPRESSION = NONE);
GO
Remember you should select any one kind of compression for your data table or index. You cannot apply both the kind of compressions together.
Let me know what you think of this blog post. If you want I can also create a video on this topic on my YouTube Channel – SQL in Sixty Seconds.
Reference: Pinal Dave (http://blog.SQLAuthority.com)
Recommend
-
6
SQL Authority with Pinal Dave
-
8
SQL SERVER – Inserting sp_who2 Into a TableEarlier this week I blogged about SQL SERVER – Representing sp_who2 with DMVs
-
8
SQL SERVER – Representing sp_who2 with DMVsDuring the recent Comprehensive Database Performance Health Check, I had a very...
-
3
Attach an In-Memory Database with T-SQLSQL SERVER – Attach an In-Memory Database with T-SQLEarlier I wrote a blog post about SQL SERVER – Attach a Database with T-SQL. Right afte...
-
11
SQL SERVER – DBCC DBREINDEX and MAXDOP Not PossibleYes, you read it right it is not possible to use DBCC DBREINDEX with MAXDOP hint as far as I know. If there is any method to use it and I am not familiar with it, you are welcom...
-
6
One of the conversations that keep on coming up during Comprehensive Database Performance Health Check is at what level one should s...
-
8
SQL Authority with Pinal DaveSQL SERVER – Number of Rows Read – Execution PlanRecently one of the clients sent me the following two images from the execution plan and his question was about the Number of Rows Read...
-
9
Today I am going to discuss a very interesting case which I had observed with my client while working on Comprehensive Database Performance Healt...
-
5
SQL SERVER – Delayed Durability and Flushing Log FilesI am personally not a big fan of the feature of delayed durability. I have so far not recommended it to many but there are a few of my clients of
-
7
SQL SERVER – Rebuilding Index with CompressionWe can be Rebuilding Index with Compression even if it was originally not created with compressions. Let us learn how we can do it today. I had recently discussed with my client at
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK