mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
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
This commit is contained in:
parent
695c5977c8
commit
db2687d1f3
@ -2549,7 +2549,6 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
|
||||
{
|
||||
PREDICATELOCKTARGETTAG tag;
|
||||
ItemPointer tid;
|
||||
TransactionId targetxmin;
|
||||
|
||||
if (!SerializationNeededForRead(relation, snapshot))
|
||||
return;
|
||||
@ -2559,24 +2558,9 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
|
||||
*/
|
||||
if (relation->rd_index == NULL)
|
||||
{
|
||||
TransactionId myxid;
|
||||
|
||||
targetxmin = HeapTupleHeaderGetXmin(tuple->t_data);
|
||||
|
||||
myxid = GetTopTransactionIdIfAny();
|
||||
if (TransactionIdIsValid(myxid))
|
||||
{
|
||||
if (TransactionIdFollowsOrEquals(targetxmin, TransactionXmin))
|
||||
{
|
||||
TransactionId xid = SubTransGetTopmostTransaction(targetxmin);
|
||||
|
||||
if (TransactionIdEquals(xid, myxid))
|
||||
{
|
||||
/* We wrote it; we already have a write lock. */
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If we wrote it; we already have a write lock. */
|
||||
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tuple->t_data)))
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user