Indexes For Performance
Indexes For Performance
Objectives
• Causes: Index defragmentation is caused by deleting rows from the underlying table.
• Tools:
o Rebuilding the indexes
o Coalescing the indexes
o Shrinking the indexes
ALTER INDEX <index name> REBUILD [ONLINE] [TABLESPACE <tbs name>] [LOGGING | NOLOGGING];
• Pros:
o Allows tablespace relocation and changing physical attributes.
o Can be implemented offline and online (acquires a lock on the index at switch
time).
• Cons:
o Requires free disk space equal to the index size.
• Pros:
o Always performed online without locking the index.
o Does not require more disk space.
• Cons:
o Cannot relocate to a different tablespace or change physical attributes.
o Does not deallocate free space.
o More overhead when deleted entries represent a high percentage of the index.
Shrinking the Indexes
Syntax:
• Pros:
o Can adjust the HWM (requires index lock).
o If COMPACT is not used, deallocates disk space.
• Cons:
o Cannot relocate to a different tablespace or change physical attributes.
o Cannot be used with bitmap or function-based indexes.
Operation Rebuilding the Indexes Coalescing the Indexes Shrinking the Indexes
Always online (locks
Create a new index
Can be executed offline/online Always online (no locks) involved when COMPACT
from existing index
is not used)
Efficient with slightly
Combine adjacent Efficient with highly (>20%) fragmented Efficient with slightly
(<20%) fragmented
leaf blocks indexes fragmented indexes
indexes
Reorganize blocks
under the HWM
Requires more disk space Requires less disk space Requires less disk space
then moves the
HWM
Can move the
index to different Yes No No
tablespace
Deallocate disk Disk space does not
Deallocate disk space Deallocate disk space
space change