Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Accelerating Database Performance Using Compression


Published on

Published in: Technology
  • Be the first to comment

Accelerating Database Performance Using Compression

  1. 1. Accelerating DatabasePerformanceUsingCompressionJoey D’AntoniPhiladelphia SQL Server Users Group08 May 2013
  2. 2. About Me Principal Architect SQL Server, Comcast Cable @jdanton –Twitter
  3. 3. OverviewCompression—What Does It ReallyMean?Deduplication—What isThat?What Should I Compress?Columnstore—How Is It Different?
  4. 4. Compression
  5. 5. Deduplication Specialized compression to eliminate duplicate copies ofrepeating data Real Example—InVMWare, you may have 10 copies ofWindowsrunning on same physical machine. Memory blocks (Common .dllsfor example) may be deduplicated. Backups
  6. 6. Benefits ofCompressionFaster performance on selectsLess I/O is required to return dataBetter Space Utilization on DiskMore Pages In Memory
  7. 7. Expenses ofCompressionAdded CPU CyclesSlower bulk inserts and updates*
  8. 8. SQLServerCompressionTypesRow CompressionPage Compression Prefix Compression Dictionary CompressionBackup Compression
  9. 9. RowCompression Treats fixed length datatypes like variabledatatypes
  10. 10. PageCompression Page BeforeCompressionPrefixCompressionDictionaryCompression
  11. 11. BackupCompression In all editions of SQL Server, starting with 2008R2 Always use Backup Compression (even whenyour storage team says no) Space is by default pre-allocated for estimatedsize of uncompressed backup Trace Flag 3042
  12. 12. How DoesCompressionWork? Storage Engine compresses and decompressesdata No other parts of SQL Server need tounderstand compression Application code doesn’t need to change
  13. 13. SoWhatToCompressSQL Data Compression gives a great dealof flexibilityCan compress tables, indexes and/orpartitioningCan use different methods ofcompressionHow to Decide?
  14. 14. SpaceSavings sp_estimate_data_compression_savingsWhatWon’t Compress Well Columns with numeric or fixed-length character data typeswhere most values require all the bytes allocated for thespecific data type Not much repeating data Repeating data with non-repeating prefixes Data stored out of the row FILESTREAM data
  15. 15. ApplicationWorkloadsMicrosoft advises using for RowCompression for EVERYTHING if you canspare 10% CPU. Don’t do this!Page Compression has higher overheadBe careful where you use pagecompression
  16. 16. Example-sourceMicrosoftCompressionWhitePaperTableSavingsROW %SavingsPAGE %Scans Updates Decision NotesT1 80% 90% 3.80% 57.27% ROW Low S, very highU. ROW savingsclose to PAGET2 15% 89% 92.46% 0% PAGE Very high ST3 30% 81% 27.14% 4.17% ROW Low ST4 38% 83% 89.16% 10.54% ROW High UT5 21% 87% 0.00% 0% PAGE Append ONLYtableT6 28% 87% 87.54% 0% PAGE High S, low UT7 29% 88% 0.50% 0% PAGE 99% appendsT8 30% 90% 11.44% 0.06% PAGE 85% appendsT9 84% 92% 0.02% 0.00% ROW ROW savings ~=PAGET10 15% 89% 100.00% 0.00% PAGE Read ONLY table
  17. 17. What HappenswithCompression Tables and Indexes are rebuilt using ALTERTABLE…REBUILD and ALTER INDEX..REBUILD Requires workspace, CPU and I/O Same mechanism as rebuilding an index Free workspace required in User Database Transaction Log Temp DB
  18. 18. How andWhenCompressData Online vs Offline Concurrent vs Serial Order of Compressing—start small and work up SORT_IN_TEMPDB
  19. 19. ManagingInserts andUpdatesTable organization Table compression settingROW PAGEHeap The newly inserted row isrow-compressed.The newly inserted row ispage-compressed:· if new row goes to anexisting page with pagecompression· if the new row is insertedthrough BULK INSERT withTABLOCK· if the new row is insertedthrough INSERT INTO ...(TABLOCK) SELECT ... FROMOtherwise, the row is row-compressed.*Clustered index The newly inserted row isrow-compressed.The newly inserted row ispage-compressed if new rowgoes to an existing page withpage compression Otherwise,it is row compressed until thepage fills up. Pagecompression is attemptedbefore a page split.**
  20. 20. UnderlyingDataStructuresTablecompressionTransactionlogMappingindex forrebuilding theclusteredindexSort pages forqueriesVersion store(with SI orRCSI isolationlevel)ROW ROW NONE NONE ROWPAGE ROW NONE NONE ROW
  21. 21. What isColumnstore?
  22. 22. ColumnStoreLimitationsNon UpdateableLimited DataTypesCan only be nonclustered indexNo computed columnsNo sparse columnsNo indexed viewsOne PerTable
  23. 23. Compression Demo
  24. 24. Questions
  25. 25. Contact Info@jdanton –Twitter – Email – Blog