aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/indexcmds.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-12-07 08:31:02 +0900
committerMichael Paquier <michael@paquier.xyz>2023-12-07 08:31:02 +0900
commitc426f7c2b36a5efd9bcef2a2dfcc559f7879cd84 (patch)
treeea27323aa804e9f8c4000dcd5633513e65f4ad77 /src/backend/commands/indexcmds.c
parentc2a465b2c94fb44211c350f73b5a11978d3b4536 (diff)
downloadpostgresql-c426f7c2b36a5efd9bcef2a2dfcc559f7879cd84.tar.gz
postgresql-c426f7c2b36a5efd9bcef2a2dfcc559f7879cd84.zip
Fix assertion failure with REINDEX and event triggers
A REINDEX CONCURRENTLY run on a table with no indexes would always pop the topmost snapshot from the active snapshot stack, making the snapshot handling inconsistent between the multiple-relation and single-relation cases. This commit slightly changes the snapshot stack handling so as a snapshot is popped only ReindexMultipleInternal() in this case after a relation has been reindexed, fixing a problem where an event trigger function may need a snapshot but does not have one. This also keeps the places where PopActiveSnapshot() is called closer to each other. While on it, this expands the existing tests to cover all the cases that could be faced with REINDEX commands and such event triggers, for one or more relations, with or without indexes. This behavior is inconsistent since 5dc92b844e68, but we've never had a need for an active snapshot at the end of a REINDEX until now. Thanks also to Jian He for the input. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/cb538743-484c-eb6a-a8c5-359980cd3a17@gmail.com
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r--src/backend/commands/indexcmds.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 412e1ba84f4..4ee498d9855 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -3347,6 +3347,8 @@ ReindexMultipleInternal(const ReindexStmt *stmt, const List *relids, const Reind
newparams.options |= REINDEXOPT_MISSING_OK;
(void) ReindexRelationConcurrently(stmt, relid, &newparams);
+ if (ActiveSnapshotSet())
+ PopActiveSnapshot();
/* ReindexRelationConcurrently() does the verbose output */
}
else if (relkind == RELKIND_INDEX)
@@ -3698,10 +3700,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
* session until this operation completes.
*/
if (indexIds == NIL)
- {
- PopActiveSnapshot();
return false;
- }
/* It's not a shared catalog, so refuse to move it to shared tablespace */
if (params->tablespaceOid == GLOBALTABLESPACE_OID)