3. Session Objectives And Takeaways
Session Objectives
Why data compression?
Describe data compression in SQL Server
Describe Space/Performance trade-offs
Key Takeaways
Can reduce size of a database significantly
Easy to enable/disable
No application changes
Performance gains
4. Agenda
What is the problem?
Solution
Compression in SQL Server 2008
5. Problem
Large Database
Storage Cost
Workload Performance
Manageability Cost
Backup/Recovery
6. Solution
Reduce the size of the database
Reduce the information stored
Compress the data
Compress the data file
No benefit in-memory
Need to compress larger chunks, does not scale
for random access
Store data efficiently in the row/page
(+) More data can fit in memory
(+) Better Performance for I/O bound workload
(-) Performance degradation for CPU bound workload
7. Agenda
What is the problem?
Solution
Compression in SQL Server 2008
8. Compression in SQL Server
SQL Server 2008
ROW and PAGE compression
Backup Compression
Two key changes
Efficient storage of data within
row (both for data and index)
Reduce Data Redundancy on the page
9. Efficient Storage in the ROW
Variable Length Encoding (new row format)
4-byte integer
SQL2005 0 0 0 1 4 bytes
SQL2008 1
(compression enabled)
Special Handling of NULL and 0s
CHAR data type storage optimization
10. Reduce Data Redundancy:
Column Prefix
Factor out common prefix from the same
column across all rows on the page
Store these ‘prefix’ values once and then
reference them from respective columns
Example:
Student (Name VARCHAR (10),
ID INT,
CODE VARBINARY(3))
12. Reduce Data Redundancy:
Page Dictionary
Find repeating values across all
columns on all the rows on the page
Store these values in a dictionary once and
reference them from respective columns
14. Enabling Compression
Enterprise Edition only
Types of data compressions
ROW
Stores fixed length values as variable length
Superset of vardecimal storage format
Row metadata optimized
BLOB/LOB is not ROW compressed
PAGE (includes ROW)
Column Prefix
Dictionary
Only in-row BLOB/LOB can potentially benefit from PAGE
compression
17. Data Compression TSQL Example
CREATE TABLE T (c1 int, c2 char(2000) )
WITH (DATA_COMPRESSION = ROW)
CREATE TABLE T_Part (c1 int, c2 char(2000) )
ON somePartScheme (c1)
WITH
(DATA_COMPRESSION = PAGE ON PARTITIONS (1-7),
DATA_COMPRESSION = NONE ON PARTITIONS (8) )
ALTER INDEX CI ON T REBUILD
WITH (DATA_COMPRESSION=PAGE)
ALTER INDEX CI ON T REBUILD PARTITION = 3
WITH (DATA_COMPRESSION=PAGE)
18. Enabling Compression…
Estimate space savings
sp_estimate_data_compression_savings
Space savings depend upon
Schema
Data Distribution
23. Impact Of Data Compression
Application
No changes needed in the application
Application throughput increase if I/O bound
Utilities
All Database Utilities (e.g.
Backup, Index, DBCC) fully supported
Gains if I/O bound
24. Supportability
DBCC PAGE enhanced
New Perfmon counters
Page Compression attempts/sec
Page Compressed/sec
New columns in DMVs
sys.db_index_physical_stats
compressed_pages_count
sys.db_index_operational_stats
Page_compression_success_count
Page_compression_attempt_count
25.
26. Summary – Compression
Can reduce size of database significantly
Lower total cost of ownership (TCO)
Easy to enable/disable
No application changes
Performance gains
27.
28.
29. Related Content
Breakout Sessions (session codes and titles)
Interactive Theater Sessions (session codes and titles)
Hands-on Labs (session codes and titles)
Hands-on Labs (session codes and titles)