summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/cache/relcache.c15
-rw-r--r--src/backend/utils/time/snapmgr.c8
2 files changed, 13 insertions, 10 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index d1ae761b3f6..9f54a9e72b7 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -371,14 +371,13 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic)
pg_class_desc = table_open(RelationRelationId, AccessShareLock);
/*
- * The caller might need a tuple that's newer than the one the historic
- * snapshot; currently the only case requiring to do so is looking up the
- * relfilenumber of non mapped system relations during decoding. That
- * snapshot can't change in the midst of a relcache build, so there's no
- * need to register the snapshot.
+ * The caller might need a tuple that's newer than what's visible to the
+ * historic snapshot; currently the only case requiring to do so is
+ * looking up the relfilenumber of non mapped system relations during
+ * decoding.
*/
if (force_non_historic)
- snapshot = GetNonHistoricCatalogSnapshot(RelationRelationId);
+ snapshot = RegisterSnapshot(GetNonHistoricCatalogSnapshot(RelationRelationId));
pg_class_scan = systable_beginscan(pg_class_desc, ClassOidIndexId,
indexOK && criticalRelcachesBuilt,
@@ -395,6 +394,10 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic)
/* all done */
systable_endscan(pg_class_scan);
+
+ if (snapshot)
+ UnregisterSnapshot(snapshot);
+
table_close(pg_class_desc, AccessShareLock);
return pg_class_tuple;
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index 8f1508b1ee2..6ed1c93383e 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -203,10 +203,10 @@ typedef struct SerializedSnapshotData
* GetTransactionSnapshot
* Get the appropriate snapshot for a new query in a transaction.
*
- * Note that the return value may point at static storage that will be modified
- * by future calls and by CommandCounterIncrement(). Callers should call
- * RegisterSnapshot or PushActiveSnapshot on the returned snap if it is to be
- * used very long.
+ * Note that the return value points at static storage that will be modified
+ * by future calls and by CommandCounterIncrement(). Callers must call
+ * RegisterSnapshot or PushActiveSnapshot on the returned snap before doing
+ * any other non-trivial work that could invalidate it.
*/
Snapshot
GetTransactionSnapshot(void)