aboutsummaryrefslogtreecommitdiff
path: root/src/include/access/heapam.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/access/heapam.h')
-rw-r--r--src/include/access/heapam.h85
1 files changed, 50 insertions, 35 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index b632fe953c4..a307fb5f245 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -36,8 +36,9 @@
#define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
#define HEAP_INSERT_SPECULATIVE 0x0010
-/* "options" flag bits for heap_page_prune */
+/* "options" flag bits for heap_page_prune_and_freeze */
#define HEAP_PAGE_PRUNE_MARK_UNUSED_NOW (1 << 0)
+#define HEAP_PAGE_PRUNE_FREEZE (1 << 1)
typedef struct BulkInsertStateData *BulkInsertState;
struct TupleTableSlot;
@@ -195,26 +196,49 @@ typedef struct HeapPageFreeze
} HeapPageFreeze;
/*
- * Per-page state returned from pruning
+ * Per-page state returned by heap_page_prune_and_freeze()
*/
-typedef struct PruneResult
+typedef struct PruneFreezeResult
{
int ndeleted; /* Number of tuples deleted from the page */
int nnewlpdead; /* Number of newly LP_DEAD items */
+ int nfrozen; /* Number of tuples we froze */
+
+ /* Number of live and recently dead tuples on the page, after pruning */
+ int live_tuples;
+ int recently_dead_tuples;
/*
- * Tuple visibility is only computed once for each tuple, for correctness
- * and efficiency reasons; see comment in heap_page_prune() for details.
- * This is of type int8[], instead of HTSV_Result[], so we can use -1 to
- * indicate no visibility has been computed, e.g. for LP_DEAD items.
+ * all_visible and all_frozen indicate if the all-visible and all-frozen
+ * bits in the visibility map can be set for this page, after pruning.
+ *
+ * vm_conflict_horizon is the newest xmin of live tuples on the page. The
+ * caller can use it as the conflict horizon when setting the VM bits. It
+ * is only valid if we froze some tuples (nfrozen > 0), and all_frozen is
+ * true.
*
- * This needs to be MaxHeapTuplesPerPage + 1 long as FirstOffsetNumber is
- * 1. Otherwise every access would need to subtract 1.
+ * These are only set if the HEAP_PRUNE_FREEZE option is set.
*/
- int8 htsv[MaxHeapTuplesPerPage + 1];
-} PruneResult;
+ bool all_visible;
+ bool all_frozen;
+ TransactionId vm_conflict_horizon;
-/* 'reason' codes for heap_page_prune() */
+ /*
+ * Whether or not the page makes rel truncation unsafe. This is set to
+ * 'true', even if the page contains LP_DEAD items. VACUUM will remove
+ * them before attempting to truncate.
+ */
+ bool hastup;
+
+ /*
+ * LP_DEAD items on the page after pruning. Includes existing LP_DEAD
+ * items.
+ */
+ int lpdead_items;
+ OffsetNumber deadoffsets[MaxHeapTuplesPerPage];
+} PruneFreezeResult;
+
+/* 'reason' codes for heap_page_prune_and_freeze() */
typedef enum
{
PRUNE_ON_ACCESS, /* on-access pruning */
@@ -222,20 +246,6 @@ typedef enum
PRUNE_VACUUM_CLEANUP, /* VACUUM 2nd heap pass */
} PruneReason;
-/*
- * Pruning calculates tuple visibility once and saves the results in an array
- * of int8. See PruneResult.htsv for details. This helper function is meant to
- * guard against examining visibility status array members which have not yet
- * been computed.
- */
-static inline HTSV_Result
-htsv_get_valid_status(int status)
-{
- Assert(status >= HEAPTUPLE_DEAD &&
- status <= HEAPTUPLE_DELETE_IN_PROGRESS);
- return (HTSV_Result) status;
-}
-
/* ----------------
* function prototypes for heap access method
*
@@ -309,9 +319,11 @@ extern bool heap_prepare_freeze_tuple(HeapTupleHeader tuple,
const struct VacuumCutoffs *cutoffs,
HeapPageFreeze *pagefrz,
HeapTupleFreeze *frz, bool *totally_frozen);
-extern void heap_freeze_execute_prepared(Relation rel, Buffer buffer,
- TransactionId snapshotConflictHorizon,
- HeapTupleFreeze *tuples, int ntuples);
+
+extern void heap_pre_freeze_checks(Buffer buffer,
+ HeapTupleFreeze *tuples, int ntuples);
+extern void heap_freeze_prepared_tuples(Buffer buffer,
+ HeapTupleFreeze *tuples, int ntuples);
extern bool heap_freeze_tuple(HeapTupleHeader tuple,
TransactionId relfrozenxid, TransactionId relminmxid,
TransactionId FreezeLimit, TransactionId MultiXactCutoff);
@@ -332,12 +344,15 @@ extern TransactionId heap_index_delete_tuples(Relation rel,
/* in heap/pruneheap.c */
struct GlobalVisState;
extern void heap_page_prune_opt(Relation relation, Buffer buffer);
-extern void heap_page_prune(Relation relation, Buffer buffer,
- struct GlobalVisState *vistest,
- int options,
- PruneResult *presult,
- PruneReason reason,
- OffsetNumber *off_loc);
+extern void heap_page_prune_and_freeze(Relation relation, Buffer buffer,
+ struct GlobalVisState *vistest,
+ int options,
+ struct VacuumCutoffs *cutoffs,
+ PruneFreezeResult *presult,
+ PruneReason reason,
+ OffsetNumber *off_loc,
+ TransactionId *new_relfrozen_xid,
+ MultiXactId *new_relmin_mxid);
extern void heap_page_prune_execute(Buffer buffer, bool lp_truncate_only,
OffsetNumber *redirected, int nredirected,
OffsetNumber *nowdead, int ndead,