Skip to content

Commit efaa02a

Browse files
michaelpqpull[bot]
authored andcommitted
Improve some error messages with invalid indexes for REINDEX CONCURRENTLY
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.4fm3fhk4ypshxopa@awork3.anarazel.de
1 parent 9449c06 commit efaa02a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/backend/commands/indexcmds.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,10 +3526,11 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
35263526

35273527
if (!indexRelation->rd_index->indisvalid)
35283528
ereport(WARNING,
3529-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3530-
errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
3529+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3530+
errmsg("skipping reindex of invalid index \"%s.%s\"",
35313531
get_namespace_name(get_rel_namespace(cellOid)),
3532-
get_rel_name(cellOid))));
3532+
get_rel_name(cellOid)),
3533+
errhint("Use DROP INDEX or REINDEX INDEX.")));
35333534
else if (indexRelation->rd_index->indisexclusion)
35343535
ereport(WARNING,
35353536
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -3578,10 +3579,11 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
35783579

35793580
if (!indexRelation->rd_index->indisvalid)
35803581
ereport(WARNING,
3581-
(errcode(ERRCODE_INDEX_CORRUPTED),
3582-
errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
3582+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3583+
errmsg("skipping reindex of invalid index \"%s.%s\"",
35833584
get_namespace_name(get_rel_namespace(cellOid)),
3584-
get_rel_name(cellOid))));
3585+
get_rel_name(cellOid)),
3586+
errhint("Use DROP INDEX or REINDEX INDEX.")));
35853587
else
35863588
{
35873589
ReindexIndexInfo *idx;

src/test/regress/expected/create_index.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,8 @@ DROP INDEX concur_reindex_ind5_ccnew;
25812581
DELETE FROM concur_reindex_tab4 WHERE c1 = 1;
25822582
-- The invalid index is not processed when running REINDEX TABLE.
25832583
REINDEX TABLE CONCURRENTLY concur_reindex_tab4;
2584-
WARNING: cannot reindex invalid index "public.concur_reindex_ind5" concurrently, skipping
2584+
WARNING: skipping reindex of invalid index "public.concur_reindex_ind5"
2585+
HINT: Use DROP INDEX or REINDEX INDEX.
25852586
NOTICE: table "concur_reindex_tab4" has no indexes that can be reindexed concurrently
25862587
\d concur_reindex_tab4
25872588
Table "public.concur_reindex_tab4"

0 commit comments

Comments
 (0)