aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 901fff059a1..be4905181e0 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -394,6 +394,28 @@ GetCurrentTransactionIdIfAny(void)
/*
+ * GetStableLatestTransactionIdIfAny
+ *
+ * Get the latest XID once and then return same value for rest of transaction.
+ * Acts as a useful reference point for maintenance tasks.
+ */
+TransactionId
+GetStableLatestTransactionId(void)
+{
+ static LocalTransactionId lxid = InvalidLocalTransactionId;
+ static TransactionId stablexid = InvalidTransactionId;
+
+ if (lxid != MyProc->lxid ||
+ !TransactionIdIsValid(stablexid))
+ {
+ lxid = MyProc->lxid;
+ stablexid = ReadNewTransactionId();
+ }
+
+ return stablexid;
+}
+
+/*
* AssignTransactionId
*
* Assigns a new permanent XID to the given TransactionState.