Skip to content

Commit b452900

Browse files
committed
Revert "Add single-item cache when looking at topmost XID of a subtrans XID"
This reverts commit 06f5295 as per issues with this approach, both in terms of efficiency impact and stability. First, contrary to the single-item cache for transaction IDs in transam.c, the cache may finish by not be hit for a long time, and without an invalidation mechanism to clear it, it would cause inconsistent results on wraparound for example. Second, the use of SubTransGetTopmostTransaction() for the caching has a limited impact on performance. SubTransGetParent() could have more impact, though the benchmarking of the single-item approach still needs to be proved, particularly under the conditions where SLRU lookups are stressed in parallel with overflowed snapshots (aka more than 64 subxids generated, for example). After discussion with Andres Freund. Discussion: https://postgr.es/m/20220524235250.gtt3uu5zktfkr4hv@alap3.anarazel.de
1 parent f1431f3 commit b452900

File tree

1 file changed

+0
-18
lines changed

1 file changed

+0
-18
lines changed

src/backend/access/transam/subtrans.c

-18
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@
5454
#define TransactionIdToPage(xid) ((xid) / (TransactionId) SUBTRANS_XACTS_PER_PAGE)
5555
#define TransactionIdToEntry(xid) ((xid) % (TransactionId) SUBTRANS_XACTS_PER_PAGE)
5656

57-
/*
58-
* Single-item cache for results of SubTransGetTopmostTransaction(). It's
59-
* worth having such a cache because we frequently find ourselves repeatedly
60-
* checking the same XID, for example when scanning a table just after a
61-
* bulk insert, update, or delete.
62-
*/
63-
static TransactionId cachedFetchSubXid = InvalidTransactionId;
64-
static TransactionId cachedFetchTopmostXid = InvalidTransactionId;
6557

6658
/*
6759
* Link to shared-memory data structures for SUBTRANS control
@@ -163,13 +155,6 @@ SubTransGetTopmostTransaction(TransactionId xid)
163155
/* Can't ask about stuff that might not be around anymore */
164156
Assert(TransactionIdFollowsOrEquals(xid, TransactionXmin));
165157

166-
/*
167-
* Before going to the subtrans log, check our single item cache to see if
168-
* we know the result from a previous/recent request.
169-
*/
170-
if (TransactionIdEquals(xid, cachedFetchSubXid))
171-
return cachedFetchTopmostXid;
172-
173158
while (TransactionIdIsValid(parentXid))
174159
{
175160
previousXid = parentXid;
@@ -189,9 +174,6 @@ SubTransGetTopmostTransaction(TransactionId xid)
189174

190175
Assert(TransactionIdIsValid(previousXid));
191176

192-
cachedFetchSubXid = xid;
193-
cachedFetchTopmostXid = previousXid;
194-
195177
return previousXid;
196178
}
197179

0 commit comments

Comments
 (0)