Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06f5295

Browse files
committed
Add single-item cache when looking at topmost XID of a subtrans XID
This change affects SubTransGetTopmostTransaction(), used to find thetopmost transaction ID of a given transaction ID. The cache is able tostore one value, so as we can save the backend from unnecessary lookupsat pg_subtrans/ on repetitive calls of this routine. There is a similarpractice in transam.c, for example.Author: Simon RiggsReviewed-by: Andrey Borodin, Julien RouhaudDiscussion:https://postgr.es/m/CANbhV-G8Co=yq4v4BkW7MJDqVt68K_8A48nAZ_+8UQS7LrwLEQ@mail.gmail.com
1 parentfbfe691 commit06f5295

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎src/backend/access/transam/subtrans.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
#defineTransactionIdToPage(xid) ((xid) / (TransactionId) SUBTRANS_XACTS_PER_PAGE)
5555
#defineTransactionIdToEntry(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+
staticTransactionIdcachedFetchSubXid=InvalidTransactionId;
64+
staticTransactionIdcachedFetchTopmostXid=InvalidTransactionId;
5765

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

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+
returncachedFetchTopmostXid;
172+
158173
while (TransactionIdIsValid(parentXid))
159174
{
160175
previousXid=parentXid;
@@ -174,6 +189,9 @@ SubTransGetTopmostTransaction(TransactionId xid)
174189

175190
Assert(TransactionIdIsValid(previousXid));
176191

192+
cachedFetchSubXid=xid;
193+
cachedFetchTopmostXid=previousXid;
194+
177195
returnpreviousXid;
178196
}
179197

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp