diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index 45b1859..0f8c9c8 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -593,6 +593,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, OffsetNumber offnum, maxoff; bool tupgone, + tupkeep, hastup; int prev_dead_count; int nfrozen; @@ -974,6 +975,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, tuple.t_tableOid = RelationGetRelid(onerel); tupgone = false; + tupkeep = false; switch (HeapTupleSatisfiesVacuum(&tuple, OldestXmin, buf)) { @@ -996,7 +998,10 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, */ if (HeapTupleIsHotUpdated(&tuple) || HeapTupleIsHeapOnly(&tuple)) + { nkeep += 1; + tupkeep = true; + } else tupgone = true; /* we can delete the tuple */ all_visible = false; @@ -1050,6 +1055,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, * from relation. */ nkeep += 1; + tupkeep = true; all_visible = false; break; case HEAPTUPLE_INSERT_IN_PROGRESS: @@ -1081,16 +1087,19 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, hastup = true; /* - * Each non-removable tuple must be checked to see if it needs + * Each non-removable tuple that we do not keep must be checked to see if it needs * freezing. Note we already have exclusive buffer lock. */ - if (heap_prepare_freeze_tuple(tuple.t_data, FreezeLimit, + if (!tupkeep) + { + if (heap_prepare_freeze_tuple(tuple.t_data, FreezeLimit, MultiXactCutoff, &frozen[nfrozen], &tuple_totally_frozen)) - frozen[nfrozen++].offset = offnum; + frozen[nfrozen++].offset = offnum; - if (!tuple_totally_frozen) - all_frozen = false; + if (!tuple_totally_frozen) + all_frozen = false; + } } } /* scan along page */