A fastpath for TransactionIdIsCurrentTransactionId - Mailing list pgsql-hackers

From Andy Fan
Subject A fastpath for TransactionIdIsCurrentTransactionId
Date
Msg-id CAKU4AWoko=YOq=6k+kCPZn7-XOCdExX0hwbEUb7tYX4hSd28fw@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi:

In my recent work,  I want to check if the xmin for all the tuples is CurrentTransactioniId,
then I found we can improve the  fastpath for TransactionIdIsCurrentTransactionId 
like below,  would it be safe?  This would be helpful if we have lots of sub transactionId. 

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 3596a7d7345..e4721a6cb39 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -935,8 +935,12 @@ TransactionIdIsCurrentTransactionId(TransactionId xid)
         * Likewise, InvalidTransactionId and FrozenTransactionId are certainly
         * not my transaction ID, so we can just return "false" immediately for
         * any non-normal XID.
+        *
+        * And any Transaction IDs precede TransactionXmin are certainly not
+        * my transaction ID as well.
         */
-       if (!TransactionIdIsNormal(xid))
+
+       if (TransactionIdPrecedes(xid, TransactionXmin))
                return false;

        if (TransactionIdEquals(xid, GetTopTransactionIdIfAny()))

--
Best Regards
Andy Fan

pgsql-hackers by date:

Previous
From: Markus Wanner
Date:
Subject: API stability [was: pgsql: Fix possible recovery trouble if TRUNCATE overlaps a checkpoint.]
Next
From: Bharath Rupireddy
Date:
Subject: How to generate a WAL record spanning multiple WAL files?