[PATCH v9 20/21] Move 'frz_conflict_horizon' to tighter scope
Heikki Linnakangas <heikki.linnakangas@iki.fi>
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To:
Date: 2024-03-27T21:47:24Z
Lists: pgsql-hackers
---
src/backend/access/heap/pruneheap.c | 38 ++++++++++++++---------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 2bd2e858bcd..e1eed42004f 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -273,7 +273,6 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
maxoff;
PruneState prstate;
HeapTupleData tup;
- TransactionId frz_conflict_horizon;
bool do_freeze;
bool do_prune;
bool do_hint;
@@ -391,7 +390,6 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
* all-visible, so the conflict horizon remains InvalidTransactionId.
*/
presult->vm_conflict_horizon = prstate.visibility_cutoff_xid = InvalidTransactionId;
- frz_conflict_horizon = InvalidTransactionId;
maxoff = PageGetMaxOffsetNumber(page);
tup.t_tableOid = RelationGetRelid(relation);
@@ -590,24 +588,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
}
if (do_freeze)
- {
- /*
- * We can use the visibility_cutoff_xid as our cutoff for
- * conflicts when the whole page is eligible to become all-frozen
- * in the VM once we're done with it. Otherwise we generate a
- * conservative cutoff by stepping back from OldestXmin. This
- * avoids false conflicts when hot_standby_feedback is in use.
- */
- if (prstate.all_visible_except_removable && presult->set_all_frozen)
- frz_conflict_horizon = prstate.visibility_cutoff_xid;
- else
- {
- /* Avoids false conflicts when hot_standby_feedback in use */
- frz_conflict_horizon = prstate.pagefrz.cutoffs->OldestXmin;
- TransactionIdRetreat(frz_conflict_horizon);
- }
heap_freeze_prepared_tuples(buffer, prstate.frozen, prstate.nfrozen);
- }
MarkBufferDirty(buffer);
@@ -626,8 +607,27 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
* on the standby with xids older than the youngest tuple this
* record will freeze will conflict.
*/
+ TransactionId frz_conflict_horizon = InvalidTransactionId;
TransactionId conflict_xid;
+ /*
+ * We can use the visibility_cutoff_xid as our cutoff for
+ * conflicts when the whole page is eligible to become all-frozen
+ * in the VM once we're done with it. Otherwise we generate a
+ * conservative cutoff by stepping back from OldestXmin.
+ */
+ if (do_freeze)
+ {
+ if (prstate.all_visible_except_removable && presult->set_all_frozen)
+ frz_conflict_horizon = prstate.visibility_cutoff_xid;
+ else
+ {
+ /* Avoids false conflicts when hot_standby_feedback in use */
+ frz_conflict_horizon = prstate.pagefrz.cutoffs->OldestXmin;
+ TransactionIdRetreat(frz_conflict_horizon);
+ }
+ }
+
if (TransactionIdFollows(frz_conflict_horizon, prstate.latest_xid_removed))
conflict_xid = frz_conflict_horizon;
else
--
2.40.1
--caj67xgx3lukmr5f
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="v9-0021-WIP-refactor.patch"