From 1a4bc2db6cb80a6e52aed8f5a68b895231653d6c Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Fri, 11 May 2012 14:38:11 +0100 Subject: Ensure age() returns a stable value rather than the latest value --- src/backend/access/transam/xact.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/backend/access/transam/xact.c') 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 @@ -393,6 +393,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 * -- cgit v1.2.3