In earlier versions of SQL Server, we had Page level and Row level compression. With SQL Server 2016, there are 2 new built in functions which can help you Compress and Decompress text on the fly.
With SQL Server 2016 Service Pack 1, a number of Enterprise only features were made available in the Standard and Express editions of SQL Server. Compression/Decompression is available across all editions of SQL Server with 2016 SP1.
Compress function can be used on individual columns and input expressions. It uses the GZIP algorithm behind the scene and compresses the result to a byte array of type varbinary(max).
The input expression can be of any of the character and binary datatypes – CHAR, VARCHAR, NCHAR, NVARCHAR, BINARY, VARBINARY.
Using Compression can help improve the overall performance in 3 primary ways —
- Decreased Input/Output operation between client side and server side can result in improved performance.
- Space used by the SQL Server tables will be decreased.
- Very efficient when you are working with large objects like binary data.
Performance Considerations –
- Compressed Column must be VARBINARY(MAX) only.
- Compressed Column can’t be indexed – but do you actually need to index this column? Most probably not.
- Compression/Decompression might require additional CPU resources and processing time.
- Decompress function returns the values as VARBINARY(MAX) and needs to be cast to VARCHAR so that the content is readable.