diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 8aa1f49..62811f7 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1685,10 +1685,18 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) if (old_snapshot_threshold < 0) return; - /* Keep track of the latest xmin seen by any process. */ + /* + * Keep track of the latest xmin seen by any process. We need to + * update time mapping only if xmin is changed since last time. + */ SpinLockAcquire(&oldSnapshotControl->mutex_latest_xmin); if (TransactionIdFollows(xmin, oldSnapshotControl->latest_xmin)) oldSnapshotControl->latest_xmin = xmin; + else + { + SpinLockRelease(&oldSnapshotControl->mutex_latest_xmin); + return; + } SpinLockRelease(&oldSnapshotControl->mutex_latest_xmin); /* No further tracking needed for 0 (used for testing). */