Routinely Recreating an Index

Context

When data deletion is repeatedly performed in the database, index keys will be deleted from the index page, resulting in index distention. Recreating an index routinely improves query efficiency.

The database supports B-tree, GIN, and psort indexes.

Rebuilding an Index

Use either of the following two methods to recreate an index:

Procedure

Assume the ordinary index areaS_idx exists in the area_id column of the imported table areaS. Use either of the following two methods to recreate an index:
  • Run the DROP INDEX statement to delete the index and run the CREATE INDEX statement to create an index.
    1. Delete an index.
      DROP INDEX areaS_idx;
      DROP INDEX
    2. Create an index.
      CREATE INDEX areaS_idx ON areaS (area_id);
      CREATE INDEX
  • Run the REINDEX statement to recreate an index.
    • Run the REINDEX TABLE statement to recreate an index.
      REINDEX TABLE areaS;
      REINDEX
    • Run the REINDEX INTERNAL TABLE statement to recreate an index for a desc table ().
      REINDEX INTERNAL TABLE areaS;
      REINDEX