1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Ensure age() returns a stable value rather than the latest value

This commit is contained in:
Simon Riggs
2012-05-11 14:36:24 +01:00
parent 3652d72dd4
commit b06679e012
3 changed files with 26 additions and 5 deletions

View File

@ -391,6 +391,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
*