mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44: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;
|
PREDICATELOCKTARGETTAG tag;
|
||||||
ItemPointer tid;
|
ItemPointer tid;
|
||||||
TransactionId targetxmin;
|
|
||||||
|
|
||||||
if (!SerializationNeededForRead(relation, snapshot))
|
if (!SerializationNeededForRead(relation, snapshot))
|
||||||
return;
|
return;
|
||||||
@ -2559,25 +2558,10 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
|
|||||||
*/
|
*/
|
||||||
if (relation->rd_index == NULL)
|
if (relation->rd_index == NULL)
|
||||||
{
|
{
|
||||||
TransactionId myxid;
|
/* If we wrote it; we already have a write lock. */
|
||||||
|
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tuple->t_data)))
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do quick-but-not-definitive test for a relation lock first. This will
|
* Do quick-but-not-definitive test for a relation lock first. This will
|
||||||
|
Loading…
x
Reference in New Issue
Block a user