aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gin/ginfast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/gin/ginfast.c')
-rw-r--r--src/backend/access/gin/ginfast.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index c8fe7c78a7a..8798fbe9635 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -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);