Download presentation
Presentation is loading. Please wait.
1
Nifty trick to compress LOB data
Phil Grayson Aireforge.com
2
Phil Grayson @databoffin
Consultant at xTEN Chief ticket creator at Aireforge Organizer of Data n’ Gravy & Leeds Data Platform UG Friend of Redgate, SQLBits Blogs: philgrayson.me, blog.aireforge.com, blog.xten.uk 19 years of SQL Server experience (7.0 to 2019)
3
Data compression options
Row Compression Page Compression Columnstore Columnstore Archival
4
COMPRESS() & UNCOMPRESS()
To Compress COMPRESS('String here'); Returns varbinary(max) To Decompress CAST(DECOMPRESS('String here') AS VARCHAR(512)) AS Text; Note: For SQL Server 2016 use a GZIP CLR function Supported Datatypes binary(n) char(n) nchar(n) nvarchar(max) nvarchar(n) varbinary(max) varbinary(n) varchar(max) varchar(n)
5
SELECT TOP(10) * FROM dbo.Requests
6
Check the sizes Max row length Max row length (after compression)
SELECT MAX(LEN(Payload)) FROM dbo.Requests; --8,000 Max row length (after compression) SELECT MAX(LEN(COMPRESS(Payload))) FROM dbo.Requests; --1,375 (82.8%) NOTE: This allows for VARBINARY(2000)
7
SELECT TOP(10) * FROM dbo.Requests
8
Computed columns
9
Computed columns CREATE TABLE [dbo].[Requests_Compress] (
[RequestID] [INT] IDENTITY(1, 1) PRIMARY KEY CLUSTERED NOT NULL, [Payload] AS (CONVERT([VARCHAR](MAX), DECOMPRESS([Payload_Compressed]), (0))), [Payload_Compressed] [VARBINARY](2000) NOT NULL ); INSERT INTO [dbo].[Requests_Compress] (Payload_Compressed) SELECT CONVERT(VARBINARY(2000), COMPRESS(Payload)) AS Payload_Compressed FROM dbo.Requests;
10
Comparing compression
4015GB Uncompressed Data 721MB Compress -82% Reduction 680MB Compress + Page -83% Reduction -5.7% Extra 668MB Compress + Row -7.3% Extra
11
Things to remember Requires a code change
Compressed data & computed columns can’t be indexed INSERT, UPDATE & DELETE overhead Durable computed columns will consume more space
12
And that’s it. Any questions?
Download Aireforge Studio from aireforge.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.