aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/brin
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2023-10-30 14:46:05 -0700
committerNoah Misch <noah@leadboat.com>2023-10-30 14:46:05 -0700
commit13503eb5905b51d22d86a3c2065c241a61cedd44 (patch)
tree2c85ea70d89714b5dd05a60b058be2162d09982e /src/backend/access/brin
parent6ec9e9975eff5260651d84ed8bcfd8ecb08e5fbb (diff)
downloadpostgresql-13503eb5905b51d22d86a3c2065c241a61cedd44.tar.gz
postgresql-13503eb5905b51d22d86a3c2065c241a61cedd44.zip
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
Diffstat (limited to 'src/backend/access/brin')
-rw-r--r--src/backend/access/brin/brin.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index af392bc032b..25338a90e29 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -1100,8 +1100,14 @@ brin_summarize_range(PG_FUNCTION_ARGS)
errmsg("could not open parent table of index \"%s\"",
RelationGetRelationName(indexRel))));
- /* OK, do it */
- brinsummarize(indexRel, heapRel, heapBlk, true, &numSummarized, NULL);
+ /* see gin_clean_pending_list() */
+ if (indexRel->rd_index->indisvalid)
+ brinsummarize(indexRel, heapRel, heapBlk, true, &numSummarized, NULL);
+ else
+ ereport(DEBUG1,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("index \"%s\" is not valid",
+ RelationGetRelationName(indexRel))));
/* Roll back any GUC changes executed by index functions */
AtEOXact_GUC(false, save_nestlevel);
@@ -1183,12 +1189,21 @@ brin_desummarize_range(PG_FUNCTION_ARGS)
errmsg("could not open parent table of index \"%s\"",
RelationGetRelationName(indexRel))));
- /* the revmap does the hard work */
- do
+ /* see gin_clean_pending_list() */
+ if (indexRel->rd_index->indisvalid)
{
- done = brinRevmapDesummarizeRange(indexRel, heapBlk);
+ /* the revmap does the hard work */
+ do
+ {
+ done = brinRevmapDesummarizeRange(indexRel, heapBlk);
+ }
+ while (!done);
}
- while (!done);
+ else
+ ereport(DEBUG1,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("index \"%s\" is not valid",
+ RelationGetRelationName(indexRel))));
relation_close(indexRel, ShareUpdateExclusiveLock);
relation_close(heapRel, ShareUpdateExclusiveLock);