Skip to content

Commit db2687d

Browse files
committed
Optimize PredicateLockTuple().
PredicateLockTuple() has a fast exit if tuple was written by the current transaction, as in that case it already has a lock. This check can be performed using TransactionIdIsCurrentTransactionId() instead of SubTransGetTopmostTransaction(), to avoid any chance of having to hit the disk. Author: Ashwin Agrawal, based on a suggestion from Andres Freund Reviewed-by: Thomas Munro Discussion: https://postgr.es/m/CALfoeiv0k3hkEb3Oqk%3DziWqtyk2Jys1UOK5hwRBNeANT_yX%2Bng%40mail.gmail.com
1 parent 695c597 commit db2687d

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/backend/storage/lmgr/predicate.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,6 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
25492549
{
25502550
PREDICATELOCKTARGETTAG tag;
25512551
ItemPointer tid;
2552-
TransactionId targetxmin;
25532552

25542553
if (!SerializationNeededForRead(relation, snapshot))
25552554
return;
@@ -2559,24 +2558,9 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
25592558
*/
25602559
if (relation->rd_index == NULL)
25612560
{
2562-
TransactionId myxid;
2563-
2564-
targetxmin = HeapTupleHeaderGetXmin(tuple->t_data);
2565-
2566-
myxid = GetTopTransactionIdIfAny();
2567-
if (TransactionIdIsValid(myxid))
2568-
{
2569-
if (TransactionIdFollowsOrEquals(targetxmin, TransactionXmin))
2570-
{
2571-
TransactionId xid = SubTransGetTopmostTransaction(targetxmin);
2572-
2573-
if (TransactionIdEquals(xid, myxid))
2574-
{
2575-
/* We wrote it; we already have a write lock. */
2576-
return;
2577-
}
2578-
}
2579-
}
2561+
/* If we wrote it; we already have a write lock. */
2562+
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tuple->t_data)))
2563+
return;
25802564
}
25812565

25822566
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy