| My OracleGuide | Compressing Indexes | About Feedback | Products |
|
What is Index Compression? Oracle introduced a compression option for indexes in Oracle 8.1. You can create an index as compressed, or rebuild it to compress it. Key compression lets you compress portions of the primary key column values in an index or index-organized table, which reduces the storage overhead of repeated values. Key compression breaks the index key into a prefix entry (the grouping piece) and a suffix entry (the unique piece). Compression is achieved by sharing the prefix entries among the suffix entries in an index block. Only keys in the leaf blocks of a B-tree index are compressed. In the branch blocks the key suffix can be truncated, but the key is not compressed. Key compression is done within an index block but not across multiple index blocks. Suffix entries form the compressed version of index rows. Each suffix entry references a prefix entry, which is stored in the same index block as the suffix entry. . The maximum prefix length for a nonunique index is the number of key columns, and the maximum prefix length for a unique index is the number of key columns minus one. Prefix entries are written to the index block only if the index block does not already contain a prefix entry whose value is equal to the present prefix entry. Prefix entries are available for sharing immediately after being written to the index block and remain available until the last deleted referencing suffix entry is cleaned out of the index block.
Performance and Storage Considerations
Uses of Key Compression
But compressing indexes, especially compressing the wrong number of columns, can have negative impact on your performance. If you compress more columns than you should, the 'compressed' index may be larger than the uncompressed index.
Validating indexes for Compression How did I know that I should compress just the first two columns of the t1_ci_1 index ? (Apart from knowing the data, that is): The validate command in sql*plus can be used to estimate the benefits of compression. Consider the following example
SQL> create table my_objects as select object_name oname, object_type otype from all_objects;
Table created.
SQL> select count(*) from my_objects;
COUNT(*)
----------
5737
SQL> select count(distinct otype) from my_objects;
COUNT(DISTINCTOTYPE)
--------------------
18
SQL> create index my_obj_idx1 on my_objects(otype, oname);
Index created.
SQL> validate index my_obj_idx1;
Index analyzed.
SQL> select opt_cmpr_count, opt_cmpr_pctsave from index_stats;
OPT_CMPR_COUNT OPT_CMPR_PCTSAVE
-------------- ----------------
1 19
In the above example, using compression will use only use 19% of the space. So compression is recommended. |