Skip to content

Commit 952365c

Browse files
committed
Remove unnecessary GetTransactionSnapshot() calls
In get_database_list() and get_subscription_list(), the GetTransactionSnapshot() call is not required because the catalog table scans use the catalog snapshot, which is held until the end of the scan. See table_beginscan_catalog(), which calls RegisterSnapshot(GetCatalogSnapshot(relid)). In InitPostgres, it's a little less obvious that it's not required, but still true I believe. All the catalog lookups in InitPostgres() also use the catalog snapshot, and the looked up values are copied while still holding the snapshot. Furthermore, as the removed FIXME comments said, calling GetTransactionSnapshot() didn't really prevent MyProc->xmin from being reset anyway. Discussion: https://www.postgresql.org/message-id/7c56f180-b9e1-481e-8c1d-efa63de3ecbb@iki.fi
1 parent 7ec4b9f commit 952365c

File tree

3 files changed

+3
-32
lines changed

3 files changed

+3
-32
lines changed

src/backend/postmaster/autovacuum.c

+1-10
Original file line numberDiff line numberDiff line change
@@ -1799,18 +1799,9 @@ get_database_list(void)
17991799
resultcxt = CurrentMemoryContext;
18001800

18011801
/*
1802-
* Start a transaction so we can access pg_database, and get a snapshot.
1803-
* We don't have a use for the snapshot itself, but we're interested in
1804-
* the secondary effect that it sets RecentGlobalXmin. (This is critical
1805-
* for anything that reads heap pages, because HOT may decide to prune
1806-
* them even if the process doesn't attempt to modify any tuples.)
1807-
*
1808-
* FIXME: This comment is inaccurate / the code buggy. A snapshot that is
1809-
* not pushed/active does not reliably prevent HOT pruning (->xmin could
1810-
* e.g. be cleared when cache invalidations are processed).
1802+
* Start a transaction so we can access pg_database.
18111803
*/
18121804
StartTransactionCommand();
1813-
(void) GetTransactionSnapshot();
18141805

18151806
rel = table_open(DatabaseRelationId, AccessShareLock);
18161807
scan = table_beginscan_catalog(rel, 0, NULL);

src/backend/replication/logical/launcher.c

+1-10
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,9 @@ get_subscription_list(void)
121121
resultcxt = CurrentMemoryContext;
122122

123123
/*
124-
* Start a transaction so we can access pg_database, and get a snapshot.
125-
* We don't have a use for the snapshot itself, but we're interested in
126-
* the secondary effect that it sets RecentGlobalXmin. (This is critical
127-
* for anything that reads heap pages, because HOT may decide to prune
128-
* them even if the process doesn't attempt to modify any tuples.)
129-
*
130-
* FIXME: This comment is inaccurate / the code buggy. A snapshot that is
131-
* not pushed/active does not reliably prevent HOT pruning (->xmin could
132-
* e.g. be cleared when cache invalidations are processed).
124+
* Start a transaction so we can access pg_subscription.
133125
*/
134126
StartTransactionCommand();
135-
(void) GetTransactionSnapshot();
136127

137128
rel = table_open(SubscriptionRelationId, AccessShareLock);
138129
scan = table_beginscan_catalog(rel, 0, NULL);

src/backend/utils/init/postinit.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -813,16 +813,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
813813
}
814814

815815
/*
816-
* Start a new transaction here before first access to db, and get a
817-
* snapshot. We don't have a use for the snapshot itself, but we're
818-
* interested in the secondary effect that it sets RecentGlobalXmin. (This
819-
* is critical for anything that reads heap pages, because HOT may decide
820-
* to prune them even if the process doesn't attempt to modify any
821-
* tuples.)
822-
*
823-
* FIXME: This comment is inaccurate / the code buggy. A snapshot that is
824-
* not pushed/active does not reliably prevent HOT pruning (->xmin could
825-
* e.g. be cleared when cache invalidations are processed).
816+
* Start a new transaction here before first access to db.
826817
*/
827818
if (!bootstrap)
828819
{
@@ -837,8 +828,6 @@ InitPostgres(const char *in_dbname, Oid dboid,
837828
* Fortunately, "read committed" is plenty good enough.
838829
*/
839830
XactIsoLevel = XACT_READ_COMMITTED;
840-
841-
(void) GetTransactionSnapshot();
842831
}
843832

844833
/*

0 commit comments

Comments
 (0)