Presentation is loading. Please wait.

Presentation is loading. Please wait.

Adding Lightness Better Performance through Compression

Similar presentations


Presentation on theme: "Adding Lightness Better Performance through Compression"— Presentation transcript:

1 Adding Lightness Better Performance through Compression
SQL Saturday #474 - Salt Lake City Jay Robinson

2 Thanks to our Sponsors! Yearly Partners Gold Sponsors

3 Adding Lightness: A Thesis
Data compression in SQL Server is not a strategy for consuming less disk space. It is a strategy for improving performance. This session will cover how it works, how to use it, when to use it, and how to take it into consideration when designing your data architecture.

4 The Obligatory Bio Page
Jay Robinson Senior Systems Engineer, Salesforce Marketing Cloud (formerly ExactTarget) Supporting hundreds of instances of SQL Server across multiple data centers Blog: downshiftdata.wordpress.com

5 “Simplify, then add lightness” Colin Chapman, Founder of Lotus
With Jim Clark in the Lotus 49 after winning the 1967 Dutch Grand Prix at Zandvoort, the car’s first race.

6 1. Who Can Use It? Introduced in SQL Server 2008
Only available in Enterprise and Developer Editions (and 2008 R2’s Datacenter Edition) From MSDN: “The details of data compression are subject to change without notice in service packs or subsequent releases.”

7 2. What Will It NOT Do? Compress system tables
Change the maximum row size on a page from 8060 bytes Compress a table when the overhead pushes the row size past 8060 Compress LOB pages?!?!

8 3. How Is It Added? For new tables and indexes...
CREATE TABLE table_name (...) WITH (DATA_COMPRESSION = ROW|PAGE); CREATE INDEX index_name ON table_name (...) WITH (DATA_COMPRESSION = ROW|PAGE, ONLINE = ON); For existing tables and indexes... ALTER TABLE table_name REBUILD ALTER INDEX index_name ON table_name REBUILD

9 4. What Is Row Compression?
Meta overhead is reduced (usually) Blanks removed from fixed strings Smaller data types are used Some types benefit, others do not. Beneficiaries: smallint, int, bigint, decimal, numeric, bit, smallmoney, money, float, real, datetime, datetime2, datetimeoffset, char, nchar, binary, timestamp

10 5. What Is Page Compression?
LastName Smith Smithfield Smithwick &1 = “Smith” Page compression includes: Row compression Prefix compression Repeated string prefixes are replaced with a pointer to the prefix in the page header Dictionary compression Repeated strings are replaced with a pointer to the string in the page header Occurs when pages are full and a row is added Leaf level only LastName &1 &1field &1wick Address 123 Cherry St. 456 Cherry Ln. 78 Cherry Ave. 90 Cherry Rd. &2 = “ Cherry ” Address 123&2St. 456&2Ln. 78&2Ave. 90&2Rd.

11 6. How Are Indexes Compressed?
The table (aka clustered index) and each non-clustered index can be compressed differently (none, row, or page). Reminder: leaf nodes of the non-clustered index contain all clustered index columns and included columns. Column Data Type Index SiteId int clustered, primary key SiteName varchar(100) Url nvarchar(256) non-clustered Url Url, SiteId

12 7. How Are Heaps Compressed?
Heaps will only use PAGE compression under certain (odd) circumstances: Bulk operations ALTER TABLE ... REBUILD A compressed clustered index is applied then removed Non-clustered indexes will need to be rebuilt to reset the page pointers

13 8. What About Other Caveats?
Indexed views can also be compressed Partitioned tables and indexes have each partition compressed separately Columnstore tables and indexes have their own compression Not configurable Can be further compressed with archival compression Not compatible with sparse columns

14 9. How Much Will You Gain? SQL Server 2014 + only
EXEC dbo.sp_estimate_data_compression_savings @schema_name = N'Sales', @object_name = N'SalesOrderDetail', @index_id = 1, @partition_number = 1, @data_compression = 'PAGE';

15 sp_estimate_data_compression_savings
DEMO sp_estimate_data_compression_savings

16 10. Why Does It Matter? Which wait types are more prevalent in your system? PAGEIOLATCH_SH and PAGEIOLATCH_EX SOS_SCHEDULER_YIELD Compression is a trade-off of CPU time for disk space. Most of our systems are IO-bound, not CPU-bound. We can afford this trade-off!

17 No Compression versus Row Compression Page Compression
DEMO No Compression versus Row Compression Page Compression

18 Thank You! "Adding power makes you faster on the straights; subtracting weight makes you faster everywhere“ - Colin Chapman Don’t Forget The Survey! Jay Robinson Blog: downshiftdata.wordpress.com


Download ppt "Adding Lightness Better Performance through Compression"

Similar presentations


Ads by Google