Introduce 'options' argument to heap_page_prune()
authorHeikki Linnakangas <[email protected]>
Mon, 1 Apr 2024 21:56:05 +0000 (00:56 +0300)
committerHeikki Linnakangas <[email protected]>
Mon, 1 Apr 2024 21:56:05 +0000 (00:56 +0300)
Currently there is only one option, HEAP_PAGE_PRUNE_MARK_UNUSED_NOW
which replaces the old boolean argument, but upcoming patches will
introduce at least one more. Having a lot of boolean arguments makes
it hard to see at the call sites what the arguments mean, so prefer a
bitmask of options with human-readable names.

Author: Melanie Plageman <[email protected]>
Author: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/20240401172219.fngjosaqdgqqvg4e@liskov

src/backend/access/heap/pruneheap.c
src/backend/access/heap/vacuumlazy.c
src/include/access/heapam.h

index 5dd37b5a376b7ac7fcb44876cf49d02762ecaf3b..ef563e19aa59daf08ffb5271d93f82f9123a4dbe 100644 (file)
@@ -166,7 +166,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
             * not the relation has indexes, since we cannot safely determine
             * that during on-access pruning with the current implementation.
             */
-           heap_page_prune(relation, buffer, vistest, false,
+           heap_page_prune(relation, buffer, vistest, 0,
                            &presult, PRUNE_ON_ACCESS, &dummy_off_loc);
 
            /*
@@ -211,8 +211,9 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
  * vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD
  * (see heap_prune_satisfies_vacuum).
  *
- * mark_unused_now indicates whether or not dead items can be set LP_UNUSED
- * during pruning.
+ * options:
+ *   MARK_UNUSED_NOW indicates that dead items can be set LP_UNUSED during
+ *   pruning.
  *
  * presult contains output parameters needed by callers such as the number of
  * tuples removed and the number of line pointers newly marked LP_DEAD.
@@ -227,7 +228,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
 void
 heap_page_prune(Relation relation, Buffer buffer,
                GlobalVisState *vistest,
-               bool mark_unused_now,
+               int options,
                PruneResult *presult,
                PruneReason reason,
                OffsetNumber *off_loc)
@@ -252,7 +253,7 @@ heap_page_prune(Relation relation, Buffer buffer,
     */
    prstate.new_prune_xid = InvalidTransactionId;
    prstate.vistest = vistest;
-   prstate.mark_unused_now = mark_unused_now;
+   prstate.mark_unused_now = (options & HEAP_PAGE_PRUNE_MARK_UNUSED_NOW) != 0;
    prstate.snapshotConflictHorizon = InvalidTransactionId;
    prstate.nredirected = prstate.ndead = prstate.nunused = 0;
    prstate.ndeleted = 0;
index ba5b7083a3a6c3cbbfbea290c1245ae7febcf405..9adb33ce9d36d0a6d9fe6bf38ff15f081bfb103f 100644 (file)
@@ -1425,6 +1425,7 @@ lazy_scan_prune(LVRelState *vacrel,
    bool        all_visible,
                all_frozen;
    TransactionId visibility_cutoff_xid;
+   int         prune_options = 0;
    int64       fpi_before = pgWalUsage.wal_fpi;
    OffsetNumber deadoffsets[MaxHeapTuplesPerPage];
    HeapTupleFreeze frozen[MaxHeapTuplesPerPage];
@@ -1458,10 +1459,12 @@ lazy_scan_prune(LVRelState *vacrel,
     * that were deleted from indexes.
     *
     * If the relation has no indexes, we can immediately mark would-be dead
-    * items LP_UNUSED, so mark_unused_now should be true if no indexes and
-    * false otherwise.
+    * items LP_UNUSED.
     */
-   heap_page_prune(rel, buf, vacrel->vistest, vacrel->nindexes == 0,
+   prune_options = 0;
+   if (vacrel->nindexes == 0)
+       prune_options = HEAP_PAGE_PRUNE_MARK_UNUSED_NOW;
+   heap_page_prune(rel, buf, vacrel->vistest, prune_options,
                    &presult, PRUNE_VACUUM_SCAN, &vacrel->offnum);
 
    /*
index 32a3fbce961d9e1d9087c67f3da59be143742558..b632fe953c4ca9f774af558edb9148876e14d153 100644 (file)
@@ -36,6 +36,9 @@
 #define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
 #define HEAP_INSERT_SPECULATIVE 0x0010
 
+/* "options" flag bits for heap_page_prune */
+#define HEAP_PAGE_PRUNE_MARK_UNUSED_NOW        (1 << 0)
+
 typedef struct BulkInsertStateData *BulkInsertState;
 struct TupleTableSlot;
 struct VacuumCutoffs;
@@ -331,7 +334,7 @@ struct GlobalVisState;
 extern void heap_page_prune_opt(Relation relation, Buffer buffer);
 extern void heap_page_prune(Relation relation, Buffer buffer,
                            struct GlobalVisState *vistest,
-                           bool mark_unused_now,
+                           int options,
                            PruneResult *presult,
                            PruneReason reason,
                            OffsetNumber *off_loc);