diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 4fdb549099..791958a543 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -6800,9 +6800,10 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, xl_heap_freeze_tuple *frz, bool *totally_frozen_p) { bool changed = false; - bool freeze_xmax = false; + bool xmin_frozen = false; /* is xmin frozen after this? */ + bool freeze_xmax = false; /* whether to freeze xmax now */ + bool xmax_frozen = false; /* ix xmax frozen after this? */ TransactionId xid; - bool totally_frozen = true; frz->frzflags = 0; frz->t_infomask2 = tuple->t_infomask2; @@ -6829,10 +6830,11 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, frz->t_infomask |= HEAP_XMIN_FROZEN; changed = true; + xmin_frozen = true; } - else - totally_frozen = false; } + else if (HeapTupleHeaderXminFrozen(tuple)) + xmin_frozen = true; /* * Process xmax. To thoroughly examine the current Xmax value we need to @@ -6870,7 +6872,6 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, if (flags & FRM_MARK_COMMITTED) frz->t_infomask |= HEAP_XMAX_COMMITTED; changed = true; - totally_frozen = false; } else if (flags & FRM_RETURN_IS_MULTI) { @@ -6892,7 +6893,6 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, frz->xmax = newxmax; changed = true; - totally_frozen = false; } else { @@ -6923,9 +6923,10 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, xid))); freeze_xmax = true; } - else - totally_frozen = false; } + else if (((tuple->t_infomask & HEAP_XMAX_INVALID) == HEAP_XMAX_INVALID) || + !TransactionIdIsValid(HeapTupleHeaderGetRawXmax(tuple))) + xmax_frozen = true; if (freeze_xmax) { @@ -6941,6 +6942,7 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, frz->t_infomask2 &= ~HEAP_HOT_UPDATED; frz->t_infomask2 &= ~HEAP_KEYS_UPDATED; changed = true; + xmax_frozen = true; } /* @@ -6981,7 +6983,7 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, } } - *totally_frozen_p = totally_frozen; + *totally_frozen_p = xmin_frozen && xmax_frozen; return changed; }