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()))
--