Indexes that are padded or not padded

The NOT PADDED and PADDED options of the CREATE INDEX and ALTER INDEX statements specify how varying-length string columns are stored in an index.

You can choose not to pad varying-length string columns in the index to their maximum length (the default), or you can choose to pad them.

Begin general-use programming interface information.
If you specify the NOT PADDED clause on a CREATE INDEX statement, any varying-length columns in the index key are not padded to their maximum length. If an existing index key includes varying-length columns, you can consider altering the index to use the NOT PADDED clause. However, using the NOT PADDED clause on the ALTER INDEX statement to change the padding places the index in the REBUILD-pending (RBDP) state. You should rebuild the index to remove the RBDP state.
End general-use programming interface information.

Using the NOT PADDED clause has the following advantages:

  • DB2® can use index-only access for the varying-length columns within the index key, which enhances performance.
  • DB2 stores only actual data, which reduces the storage requirements for the index key.

However, using the NOT PADDED clause might also have the following disadvantages:

  • Index key comparisons are slower because DB2 must compare each pair of corresponding varying-length columns individually instead of comparing the entire key when the columns are padded to their maximum length.
  • DB2 stores an additional 2-byte length field for each varying-length column. Therefore, if the length of the padding (to the maximum length) is less than or equal to 2 bytes, the storage requirements could actually be greater for varying-length columns that are not padded.
Tip: Use the NOT PADDED clause to implement index-only access if your application typically accesses varying-length columns.

To control whether varying length columns are padded by default, use the PAD INDEXES BY DEFAULT option on installation panel DSNTIPE.