From 5e99b32238234cea86fc1b9195a358f05e3a8efc Mon Sep 17 00:00:00 2001 From: Ashwin Agrawal Date: Fri, 2 Aug 2019 15:02:28 -0700 Subject: [PATCH v3 1/3] Optimize TransactionIdIsCurrentTransactionId(). If 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 have separate xid for subtransactions. This optimization was proposed by Andres Freund. Author: Ashwin Agrawal Reviewed-by: Thomas Munro Discussion: https://postgr.es/m/CALfoeiv0k3hkEb3Oqk%3DziWqtyk2Jys1UOK5hwRBNeANT_yX%2Bng%40mail.gmail.com --- src/backend/access/transam/xact.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index fc55fa6d53..e5e2902465 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -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 -- 2.23.0