| My OracleGuide | More about Indexes | About Feedback | Products |
Introduction
Oracle introduced a compression option for indexes in Oracle 8.1. You can create an index as compressed, or rebuild it to compress it. A properly compressed index uses a smaller number of leaf blocks and less I/O and less amount of buffer cache. The optimizer is likely to calculate a lower cost for using that index for range scans. Compressing indexes increase the CPU cost and compressing wrong number of columns can reduce performance. If you compress more columns than you should, the 'compressed' index may be larger than the uncompressed index. The above query can be used to calculate the cardinality and can be helpful to alter an index as compressed. Global Partitioned Indexes It is possible to create Global Partitioned Indexes irrespective of whether the underlying table is partitioned or not. Partitioning is a key tool for building extremely high availability systems involving large amount of data. It can provide tremendous benefits by improving manageability, performance, and availability. Global Partitioned Indexes can reduce the height of BTree index and hence update operations are less complex. Please see the link for more examples When to rebuild indexes? When there are lots of DML operations on the table, the indexes can get fragmented. The height of the BTree index can increase. In this situation it is required to rebuild index. One option is to use the command "analyze index validate structure". The will create a single row in 'index_stats' view. The index stats table can only hold one record of information at a time, therefore you will need to analyze each index individually.Lets do some Analysis using the customer table
SQL> select count(*) from customer;
96546
SQL> create index customer_idx on customer(address);
Index created.
SQL> analyze index customer_idx compute statistics;
Index analyzed.
SQL> select leaf_blocks from user_indexes where index_name='CUSTOMER_IDX';
235
SQL> update customer set address='aa'||address;
96546 rows updated.
SQL> analyze index customer_idx compute statistics;
Index analyzed.
The index uses more blocks after DML on customer table
SQL> select leaf_blocks from user_indexes where index_name='CUSTOMER_IDX';
691
SQL> alter index customer_idx rebuild;
Index altered.
SQL> analyze index customer_idx compute statistics;
Index analyzed.
After rebuild of the index
SQL> select leaf_blocks from user_indexes where index_name='CUSTOMER_IDX';
293
SQL> analyze table customer compute statistics;
Table analyzed.
SQL> select avg_col_len from user_tab_columns where table_name='CUSTOMER' and column_name='ADDRESS';
10
When the column length changes the number of blocks also changee
SQL> update customer set address=address||address;
96546 rows updated.
SQL> analyze index customer_idx compute statistics;
Index analyzed.
SQL> select leaf_blocks from user_indexes where index_name='CUSTOMER_IDX';
1069
SQL> alter index customer_idx rebuild;
Index altered.
SQL> analyze index customer_idx compute statistics;
Index analyzed.
The number of blocks also depend on the Average column length
SQL> select leaf_blocks from user_indexes where index_name='CUSTOMER_IDX';
425
SQL> analyze table customer compute statistics;
Table analyzed.
SQL> select avg_col_len from user_tab_columns where table_name='CUSTOMER' and column_name='ADDRESS';
20
Lets calculate the number of blocks manually
SQL> select 8196*(100-PCT_FREE)/100 from user_indexes where index_name='CUSTOMER_IDX';
7376.4
SQL> select 96546*20/7376.4 from dual;
261.769969
From the above it is found that 261 blocks are required for storing the column value alone and 163 blocks are used for storing the BTree information. |