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:
@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user