Wednesday, June 15, 2011

Rebuilding Indexes


You can use the ALTER INDEX REBUILD command to change the storage and tablespace parameters for an existing index without having to drop it.
The following is an example of an index rebuild via this command. It's storage parameters are changed to use an initial extent size of 3MB and a next extent size of 500K. It is also being moved from the USR7 tablespace to the IDX7 tablespace.
ALTER INDEX fuzzy_pink_slippers REBUILD
(  STORAGE(INITIAL 3M NEXT 500K
           PCTINCREASE 0)
TABLESPACE IDX7;  )
alter index <index_name> REBUILD TABLESPACE <new_tablespace>;

Rebuild? There is an alternative
You may wish to consider.
ALTER INDEX vmoore COALESCE;
Coalescing an index, de-fragments the leaf blocks for an index as opposed to a full rebuild cycle. In many instances, this may be sufficient remedial action.
Positives
- Less resource used - in fact no additional space is required
- Faster (typically)
- Good for databases with large block sizes (see the negative point below on index height)
Negatives
- You aren't recreating anything, so obviously you cannot move the index or adjust its storage parameters during a coalesce
- Since only the leaf blocks are coalesced, the height of the index tree will not be changed. For databases with larger block sizes, this should be less significant since the indexes will be "flatter" anyway.
  

No comments:

Post a Comment