Presentation is loading. Please wait.

Presentation is loading. Please wait.

Table Compression in Oracle9i R2 Plamen Zyumbyulev INSIDE OUT,, Let someone k n o w ”

Similar presentations


Presentation on theme: "Table Compression in Oracle9i R2 Plamen Zyumbyulev INSIDE OUT,, Let someone k n o w ”"— Presentation transcript:

1

2 Table Compression in Oracle9i R2 Plamen Zyumbyulev INSIDE OUT,, Let someone k n o w ”

3 Agenda  Overview Table Compression  How does it work?  Test Environment  Space Savings  Query Performance  Conclusion

4 Table Compression Facts  Table compression is useful  Everyone benefits from space saving  It not only saves space but can increase performance  It can’t be implemented everywhere

5 Why Table Compression ?  Table Compression increases: –I/O-subsystem capacity –I/O throughput –query scan performance (mainly FTS) –buffer cache capacity  Table Compression: –reduces cost of ownership –is easy to use –requires minimal table definition changes –is transparent to applications

6 Overview: Table Compression  Compression algorithm is based on removing data redundancy  Tables and Materialized Views can be compressed –Compression can also be specified at the partition level and tablespace level –Indexes and index-organized tables are not compressed with this method (there are other methods for index and IOT compression)  Compression is dependent upon the actual data  DDL/DML commands are supported on compressed tables  Table columns cannot neither be added nor deleted from a compressed table.

7 Which Applications benefit from Table Compression?  Table Compression targets read intensive applications such as Decision Support and OLAP  All schema designs benefit from Compression

8 Agenda  Overview Table Compression  How does it work?  Test Environment  Space Savings  Query Performance  Conclusion

9 How does Table Compression work?  Data is compressed by eliminating duplicate values in a database block First Name Last Name Scott Smith Henry Smith Henry Scott Henry-Scott McGryen  Dictionary is built per block  information to uncompress data is available in each block  If column values from same or different columns have the same values, they share the same symbol table entry. Only entire column values are compressed.  Sequences of columns are compressed as one entity if a sequence of column values occurs multiple times in many rows.

10 Block Level Compression 1233033 Meyer 11 Homestead Rd 13.99 1212300 Meyer11 Homestead Rd 1.99 1243012 Meyer 11 Homestead Rd 1.99 9923032 McGryen 3 Main Street 1.99 9833023 McGryen 3 Main Street 1.99 2133056 McGryen 3 Main Street 1.99 Non-Compressed Block Block Header Free Space Block Header Compressed Block Meyer 11 Homestead Rd 1.99 McGryen 3 Main Street 123303313.99 1212300 1243012 9923032 33023 98 2133056 Free Space Symbol Table Invoice CustName CustAddr Sales_amt 1233033 Meyer 11 Homestead Rd 13.99 1212300 Meyer 11 Homestead Rd 1.99 1243012 Meyer 11 Homestead Rd 1.99 9923032 McGryen 3 Main Street 1.99 9833023 McGryen 3 Main Street 1.99 2133056 McGryen 3 Main Street 1.99

11 How Table Compression works  All columns are considered for compression  Only worthwhile compression is performed  Symbol table is created within each database block depending on block content –Self tuning symbol table is created automatically by the system –No explicit declaration of symbol table entries –Compression algorithm automatically adapts to changes in data distribution

12 Which data is compressed  Compression occurs only when data is inserted with a bulk (direct-path) insert operation. –Direct Path SQL*Loader – insert /*+ append */ … – create table … as select … – alter table move …  A table can consist of compressed and uncompressed blocks transparently.  Any DML operation can be applied to a table storing compressed blocks. However, conventional DML operations cause records to be stored uncompressed*.

13 SQL Commands  For a new table: –Create with compress attribute in table definition create table … compress  For an existing table: 1.Alter table to add compress attribute  only new rows are compressed alter table foo compress; 2.Compress table  old and new rows are compressed alter table foo move compress;

14 Process of Compressing a Block

15 Deletes, Inserts and Updates  Deletes, Inserts and Updates are possible but can cause fragmentation and waste disk space when modifying compressed data.  Large PCTFREE will lead to low compression ratios. Setting PCTFREE to 0 (default) is recommended for all tables storing compressed data.

16 Updates  When a column is updated the algorithm checks whether a symbol table entry for the new value exists. –If it exists, the reference of the updated column is modified to the new symbol table entry and its reference count is increased by one. At the same time the reference count of the old value is decreased by one. –If no symbol table entry exists for the new column value, that value is inserted non-compressed into the row.

17 UPDATE TABLE item SET i_color = ‘green’ WHERE i_color =’blue’  If the old column value (‘green’) was also compressed and its reference count after the update operation became zero, the old symbol table entry is replaced with a new symbol table entry without touching all rows of one block. Some update operations can take advantage of compression

18 Deletes  During delete operations all references counters of the deleted rows are decreased by one. Once a reference counter becomes zero, the corresponding symbol table entry is purged.  A symbol table is never deleted from a block even if no reference into it exists because the overhead of an empty symbol table is only 4 bytes.

19 Agenda  Overview Table Compression  How does it work?  Test Environment  Space Savings  Query Performance  Conclusion

20 Test Environment:  One very big table – 2.3 TB  Table is partitioned per day.  One partition is around 3,2 GB  Once the data is loaded and processed it becomes read only.  Most of the table access is – FTS

21 Agenda  Overview Table Compression  How does it work?  Test Environment  Space Savings  Query Performance  Conclusion

22 Space Savings  Table Compression significantly reduces disk and buffer cache requirements  Compression results mostly depend on data content on block level  Definitions: Compression Factor Space Savings Non Compressed Blocks Compressed Blocks CF= Non Compressed Blocks – Compressed Blocks Non-Compressed Blocks SS= x100

23 What affects Compression? Column lengthlongshort Number distinct valueslowhigh Block size large small Sorted datayes no Column sequenceyesno Modified datayesno Column lengthlongshort Number distinct valueslowhigh Block size large small Sorted datayes no Column sequenceyesno Modified datayesno Table Characteristic Compression Factor high low

24 Estimating CF by using data samples create function compression_ratio (tabname varchar2) return number is -- sample percentage pct number := 0.000099; -- original block count (should be less than 10k) blkcnt number := 0; -- compressed block count blkcntc number; begin execute immediate ' create table TEMP_UNCOMPRESSED pctfree 0 as select * from ' || tabname || ' where rownum < 1'; while ((pct < 100) and (blkcnt < 1000)) loop execute immediate 'truncate table TEMP_UNCOMPRESSED'; execute immediate 'insert into TEMP_UNCOMPRESSED select * from ' || tabname || ' sample block (' || pct || ',10)'; execute immediate 'select count(distinct(dbms_rowid.rowid_block_number(rowid))) from TEMP_UNCOMPRESSED' into blkcnt; pct := pct * 10; end loop; execute immediate 'create table TEMP_COMPRESSED compress as select * from TEMP_UNCOMPRESSED'; execute immediate 'select count(distinct(dbms_rowid.rowid_block_number(rowid))) from TEMP_COMPRESSED' into blkcntc; execute immediate 'drop table TEMP_COMPRESSED'; execute immediate 'drop table TEMP_UNCOMPRESSED'; return (blkcnt/blkcntc); end; /

25 Ordered vs. Not ordered  The biggest CF increase comes from ordering the data

26 How Data volume affects CF 2.4 2.6 2.8 3.2 3.4 3.6 Compression Factor 135 Days in one partition 79 3.0

27 Ordered Data 1111222233334444 5555 Input Data 1234 Block1 5 Block2 4 rows per block compressed CF=2.5  Each value is compressed in one block  Symbol table contains 1 2 3 4 5  Block contains 20 values 12345 5 rows per block compressed CF=4 Block1  Not all values fit into first block  Symbol tables contains  1 2 3 4  Block contains 16 values  Symbol tables contains only 5  Block contains 4 values  20 values 1 2 3 4 5  Ordered  1 column row Sorting can also improve the clustering factor of your indexes.

28 Not Ordered Data 1234512345123451 2345 Input Data  20 values 1 2 3 4 5  Not ordered  1 column row 12345 5 rows per block compressed CF=4 Block1 CF=1 1234 Block1 5123 Block2 4512 Block3 3451 Block4 2345 Block5 4 rows per block compressed

29 Choosing the columns to order by  Sorting on fields with very low cardinality does not necessarily yield to better compression  The optimal columns to sort on seem to be those that have a table/partition-wide cardinality equal to the number of rows per block  Column correlation should be considered  The process is iterative

30 Know your data  Without a detailed understanding of the data distribution it is very difficult to predict the most optimal order.  Table/partition statistics are useful –dba_tables –dba_tab_partitons  Looking into a particular data block is very helpful –substr(rowid, 1, 15)

31 Improving ordering speed  Set SORT_AREA_SIZE for the session as big as possible. Use dedicated temp tbs with big extent size (multiple of SORT_AREA_SIZE + 1 block) If the sort needs more space:  The data is split into smaller sort runs; each piece is sorted individually.  The server process writes pieces to temporary segments on disk; these segments hold intermediate sort run data while the server works on another sort run.  The sorted pieces are merged to produce the final result.  If SORT_AREA_SIZE is not large enough to merge all the runs at once, subsets of the runs are merged in a number of merge passes.

32 Agenda  Overview Table Compression  How does it work?  Test Environment  Space Savings  Query Performance  Conclusion

33 How CF affects FTS performance  Queries are executed against compressed schema and non- compressed schema  Overall query speedup 65%

34 Query Elapsed Time Speedup  The larger the compression factor the larger the elapsed time speedup  Query speedup results from reduction in I/O- operations required –Speedup depends on the weakness of the I/O- subsystem –Speedup depends on how sparse the blocks are that the query accesses

35 Performance impact on loads and DML  On system with unlimited IO bandwidth, data load may be two times longer (even more if data need to be ordered).  Bulk loads are IO-bound on many systems.  Deleting compressed data is 10% faster.  Inserting new data is as fast as inserting into non compressed table.  UPDATE operations are 10-20% slower for compressed tables on average, mainly due to some complex optimizations that have been implemented for uncompressed tables, and not yet implemented for compressed tables.

36 Other Performance Tests Parallel load performance (CPU)

37 Delete operation CPU UtilizationUpdate operation CPU Utilization Delete/Update Performance

38 FTS Performance Parallel Full Table Scan CPU Utilization Parallel Full Table Scan IO Performance

39 Table Access by ROWID

40 Agenda  Overview Table Compression  How does it work?  Test Environment  Space Savings  Query Performance  Conclusion

41 Best Practices  Use Compression in read intensive applications  Execute bulk loads (SQLLDR and Parallel Insert) to compress rows  Compress older data in large Data Warehouses –Integrate Table Compression into the ‘rolling window’ paradigm: Compress all but most recent partition  Compress Materialized views  Only compress infrequently updated tables

42 Data normalization and Table Compression  “Normalize till it hurts, denormalize till it works”  High normalization may result in a high number of table joins (bad performance)  Both data normalization and table compression reduce redundancy

43 Conclusion  Table Compression: –reduces costs by shrinking the database footprint on disk –is transparent to applications –often improves query performance due to reduced disk I/O –increases buffer cache efficiency

44 A Q & Q U E S T I O N S A N S W E R S zyumbyulev@mobiltel.bg


Download ppt "Table Compression in Oracle9i R2 Plamen Zyumbyulev INSIDE OUT,, Let someone k n o w ”"

Similar presentations


Ads by Google