1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-19 23:22:23 +03:00

Diagnose !indisvalid in more SQL functions.

pgstatindex failed with ERRCODE_DATA_CORRUPTED, of the "can't-happen"
class XX.  The other functions succeeded on an empty index; they might
have malfunctioned if the failed index build left torn I/O or other
complex state.  Report an ERROR in statistics functions pgstatindex,
pgstatginindex, pgstathashindex, and pgstattuple.  Report DEBUG1 and
skip all index I/O in maintenance functions brin_desummarize_range,
brin_summarize_new_values, brin_summarize_range, and
gin_clean_pending_list.  Back-patch to v11 (all supported versions).

Discussion: https://postgr.es/m/20231001195309.a3@google.com
This commit is contained in:
Noah Misch
2023-10-30 14:46:05 -07:00
parent 6ec9e9975e
commit 13503eb590
4 changed files with 74 additions and 9 deletions

View File

@@ -1033,7 +1033,6 @@ gin_clean_pending_list(PG_FUNCTION_ARGS)
Oid indexoid = PG_GETARG_OID(0);
Relation indexRel = index_open(indexoid, RowExclusiveLock);
IndexBulkDeleteResult stats;
GinState ginstate;
if (RecoveryInProgress())
ereport(ERROR,
@@ -1065,8 +1064,26 @@ gin_clean_pending_list(PG_FUNCTION_ARGS)
RelationGetRelationName(indexRel));
memset(&stats, 0, sizeof(stats));
initGinState(&ginstate, indexRel);
ginInsertCleanup(&ginstate, true, true, true, &stats);
/*
* Can't assume anything about the content of an !indisready index. Make
* those a no-op, not an error, so users can just run this function on all
* indexes of the access method. Since an indisready&&!indisvalid index
* is merely awaiting missed aminsert calls, we're capable of processing
* it. Decline to do so, out of an abundance of caution.
*/
if (indexRel->rd_index->indisvalid)
{
GinState ginstate;
initGinState(&ginstate, indexRel);
ginInsertCleanup(&ginstate, true, true, true, &stats);
}
else
ereport(DEBUG1,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("index \"%s\" is not valid",
RelationGetRelationName(indexRel))));
index_close(indexRel, RowExclusiveLock);