From: | Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | A fastpath for TransactionIdIsCurrentTransactionId |
Date: | 2022-04-05 13:11:48 |
Message-ID: | CAKU4AWoko=YOq=6k+kCPZn7-XOCdExX0hwbEUb7tYX4hSd28fw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Bharath Rupireddy | 2022-04-05 13:12:55 | How to generate a WAL record spanning multiple WAL files? |
Previous Message | Markus Wanner | 2022-04-05 13:02:02 | API stability [was: pgsql: Fix possible recovery trouble if TRUNCATE overlaps a checkpoint.] |