dev compression

31

Upload: rsnarayanan

Post on 05-Jul-2015

325 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Dev Compression
Page 2: Dev Compression

Vinod Kumar MTechnology Evangelist – DB and BIMicrosoft Corporationwww.ExtremeExperts.com

Page 3: Dev Compression

Session ObjectivesWhy data compression?

Describe data compression in SQL Server

Describe Space/Performance trade-offs

Key TakeawaysCan reduce size of a database significantly

Easy to enable/disable

No application changes

Performance gains

Session Objectives And Takeaways

Page 4: Dev Compression

Agenda

What is the problem?

Solution

Compression in SQL Server 2008

Page 5: Dev Compression

Problem

Large DatabaseStorage Cost

Workload Performance

Manageability CostBackup/Recovery

Page 6: Dev Compression

Solution

Reduce the size of the databaseReduce the information stored

Compress the dataCompress 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

Page 7: Dev Compression

Agenda

What is the problem?

Solution

Compression in SQL Server 2008

Page 8: Dev Compression

Compression in SQL Server

SQL Server 2008 ROW and PAGE compression

Backup Compression

Two key changesEfficient storage of data within row (both for data and index)

Reduce Data Redundancy on the page

Page 9: Dev Compression

Efficient Storage in the ROW

Variable Length Encoding (new row format)

0 0 0 1

4-byte integer

1SQL2008 (compression enabled)

4 bytes

Special Handling of NULL and 0s

CHAR data type storage optimization

SQL2005

Page 10: Dev Compression

Reduce Data Redundancy:Column PrefixFactor 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))

Page 11: Dev Compression

Column Prefix

Page Header

0x5B8D80

0x41AABB

0x9A4041

0x112233

0x5CAABB

Lambert 5000000 NULL

4

5 20x41

20x43

20x42

Page 12: Dev Compression

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

Page 13: Dev Compression

Page Dictionary

Page Header

0x5B8D80

0x41AABB

0x9A4041

0x112233

0x5CAABB

Lambert 5000000 NULL

4

5 20x41

20x43

20x42

Column prefix

Page Dictionary

1

1

0

0

Page 14: Dev Compression

Enabling Compression

Enterprise Edition onlyTypes of data compressions

ROW Stores fixed length values as variable lengthSuperset of vardecimal storage formatRow metadata optimizedBLOB/LOB is not ROW compressed

PAGE (includes ROW)Column PrefixDictionaryOnly in-row BLOB/LOB can potentially benefit from PAGE compression

Page 15: Dev Compression

Enabling Compression Examples

Unpartitioned table

Table

Index

PAGE Compressed

Index

Uncompressed

Table

Index

Page 16: Dev Compression

Enabling Compression ExamplesLatest partition uncompressed

Jan-Mar Apr-June July-Sept Oct-Dec

PAGE Compressed

Uncompressed

ROW Compressed

Page 17: Dev Compression

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)

Page 18: Dev Compression

Enabling Compression…

Estimate space savingssp_estimate_data_compression_savings

Space savings depend uponSchema

Data Distribution

Page 19: Dev Compression

Let us estimate ….

Page 20: Dev Compression

DML Operations

INSERT (PAGE Compressed)

Header

CI structure

Header

PAGE Compressed

ROW Compressed

Page 21: Dev Compression

Table And PAGE Compression

PAGE Compressed

Uncompressed

ROW Compressed

Page 22: Dev Compression

Btree And PAGE Compression

ROOT

INTERNALINTERNAL INTERNAL

LEAFLEAFLEAFLEAF

INTERNAL

PAGE Compressed

Uncompressed

ROW Compressed

Page 23: Dev Compression

Impact Of Data Compression

ApplicationNo changes needed in the application

Application throughput increase if I/O bound

UtilitiesAll Database Utilities (e.g. Backup, Index, DBCC) fully supported

Gains if I/O bound

Page 24: Dev Compression

SupportabilityDBCC PAGE enhanced

New Perfmon countersPage Compression attempts/sec

Page Compressed/sec

New columns in DMVssys.db_index_physical_stats

compressed_pages_count

sys.db_index_operational_statsPage_compression_success_count

Page_compression_attempt_count

Page 26: Dev Compression

Summary – Compression

Can reduce size of database significantly

Lower total cost of ownership (TCO)

Easy to enable/disable

No application changes

Performance gains

Page 27: Dev Compression
Page 29: Dev Compression

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)

Page 30: Dev Compression

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4

Page 31: Dev Compression

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.