[Solved] Should I REINDEX table after large update on column not concerned by the indexes
Looking to automatically optimize YOUR SQL query? Start for free.

EverSQL Database Performance Knowledge Base

Should I REINDEX table after large update on column not concerned by the indexes

Database type:

To speed up an update on a large postgresql table, I disable the indexes :

UPDATE pg_index SET indisready=false WHERE indrelid = ( SELECT oid FROM pg_class WHERE relname='mytable')

Then run my update :

update mytable set ......

Then enable my indexes :

UPDATE pg_index SET indisready=true WHERE indrelid = ( SELECT oid FROM pg_class WHERE relname='mytable');

Then reindex :

REINDEX table mytable;

Is the last reindex necessary considering that my update is about columns not concerned by my indexes ?

Thanks for your help.

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
CREATE INDEX pg_class_idx_relname ON "pg_class" ("relname");
The optimized query:
SELECT
        pg_index.indisready 
    FROM
        pg_index 
    WHERE
        pg_index.indrelid = (
            SELECT
                pg_class.oid 
            FROM
                pg_class 
            WHERE
                pg_class.relname = 'mytable'
        )

Related Articles



* original question posted on StackOverflow here.