Improve some error messages with invalid indexes for REINDEX CONCURRENTLY
authorMichael Paquier <[email protected]>
Thu, 7 Dec 2023 05:27:54 +0000 (14:27 +0900)
committerMichael Paquier <[email protected]>
Thu, 7 Dec 2023 05:27:54 +0000 (14:27 +0900)
An invalid index is skipped when doing REINDEX CONCURRENTLY at table
level, with INDEX_CORRUPTED used as errcode.  This is confusing,
because an invalid index could exist after an interruption.  The errcode
is switched to OBJECT_NOT_IN_PREREQUISITE_STATE instead, as per a
suggestion from Andres Freund.

While on it, the error messages are reworded, and a hint is added,
telling how to rebuild an invalid index in this case.  This has been
suggested by Noah Misch.

Discussion: https://postgr.es/m/20231118230958[email protected]

src/backend/commands/indexcmds.c
src/test/regress/expected/create_index.out

index 4ee498d98552585864b4057a87f78df9ef0422bb..e56205abd8c01af1b54bccb67a21c1c981c06280 100644 (file)
@@ -3526,10 +3526,11 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
 
                    if (!indexRelation->rd_index->indisvalid)
                        ereport(WARNING,
-                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
+                               (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+                                errmsg("skipping reindex of invalid index \"%s.%s\"",
                                        get_namespace_name(get_rel_namespace(cellOid)),
-                                       get_rel_name(cellOid))));
+                                       get_rel_name(cellOid)),
+                                errhint("Use DROP INDEX or REINDEX INDEX.")));
                    else if (indexRelation->rd_index->indisexclusion)
                        ereport(WARNING,
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -3578,10 +3579,11 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
 
                        if (!indexRelation->rd_index->indisvalid)
                            ereport(WARNING,
-                                   (errcode(ERRCODE_INDEX_CORRUPTED),
-                                    errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
+                                   (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+                                    errmsg("skipping reindex of invalid index \"%s.%s\"",
                                            get_namespace_name(get_rel_namespace(cellOid)),
-                                           get_rel_name(cellOid))));
+                                           get_rel_name(cellOid)),
+                                    errhint("Use DROP INDEX or REINDEX INDEX.")));
                        else
                        {
                            ReindexIndexInfo *idx;
index acfd9d1f4f7cfc7bec71f456b5f2c4ed852bea68..446cfa678b7c1a5c2c4eee773be5cb0061506303 100644 (file)
@@ -2581,7 +2581,8 @@ DROP INDEX concur_reindex_ind5_ccnew;
 DELETE FROM concur_reindex_tab4 WHERE c1 = 1;
 -- The invalid index is not processed when running REINDEX TABLE.
 REINDEX TABLE CONCURRENTLY concur_reindex_tab4;
-WARNING:  cannot reindex invalid index "public.concur_reindex_ind5" concurrently, skipping
+WARNING:  skipping reindex of invalid index "public.concur_reindex_ind5"
+HINT:  Use DROP INDEX or REINDEX INDEX.
 NOTICE:  table "concur_reindex_tab4" has no indexes that can be reindexed concurrently
 \d concur_reindex_tab4
         Table "public.concur_reindex_tab4"