Optimize TransactionIdIsCurrentTransactionId().
authorThomas Munro <[email protected]>
Mon, 11 Nov 2019 03:33:04 +0000 (16:33 +1300)
committerThomas Munro <[email protected]>
Mon, 11 Nov 2019 03:33:04 +0000 (16:33 +1300)
If the passed in xid is the current top transaction, we can do a fast
check and exit early.  This should work well for the current heap but
also works very well for proposed AMs that don't use a separate xid
for subtransactions.

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

src/backend/access/transam/xact.c

index fc55fa6d53c623cf8edddf1dce971db08c005b7b..e5e2902465aca295f631ff44d9a3796c9fcd8787 100644 (file)
@@ -871,6 +871,9 @@ TransactionIdIsCurrentTransactionId(TransactionId xid)
        if (!TransactionIdIsNormal(xid))
                return false;
 
+       if (TransactionIdEquals(xid, GetTopTransactionIdIfAny()))
+               return true;
+
        /*
         * In parallel workers, the XIDs we must consider as current are stored in
         * ParallelCurrentXids rather than the transaction-state stack.  Note that