Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d0f730

Browse filesBrowse files
committed
Introduce 'options' argument to heap_page_prune()
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 <melanieplageman@gmail.com> Author: Heikki Linnakangas <heikki.linnakangas@iki.fi> Discussion: https://www.postgresql.org/message-id/20240401172219.fngjosaqdgqqvg4e@liskov
1 parent 959b38d commit 3d0f730
Copy full SHA for 3d0f730

File tree

Expand file treeCollapse file tree

3 files changed

+16
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-9
lines changed

‎src/backend/access/heap/pruneheap.c

Copy file name to clipboardExpand all lines: src/backend/access/heap/pruneheap.c
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
166166
* not the relation has indexes, since we cannot safely determine
167167
* that during on-access pruning with the current implementation.
168168
*/
169-
heap_page_prune(relation, buffer, vistest, false,
169+
heap_page_prune(relation, buffer, vistest, 0,
170170
&presult, PRUNE_ON_ACCESS, &dummy_off_loc);
171171

172172
/*
@@ -211,8 +211,9 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
211211
* vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD
212212
* (see heap_prune_satisfies_vacuum).
213213
*
214-
* mark_unused_now indicates whether or not dead items can be set LP_UNUSED
215-
* during pruning.
214+
* options:
215+
* MARK_UNUSED_NOW indicates that dead items can be set LP_UNUSED during
216+
* pruning.
216217
*
217218
* presult contains output parameters needed by callers such as the number of
218219
* tuples removed and the number of line pointers newly marked LP_DEAD.
@@ -227,7 +228,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
227228
void
228229
heap_page_prune(Relation relation, Buffer buffer,
229230
GlobalVisState *vistest,
230-
bool mark_unused_now,
231+
int options,
231232
PruneResult *presult,
232233
PruneReason reason,
233234
OffsetNumber *off_loc)
@@ -252,7 +253,7 @@ heap_page_prune(Relation relation, Buffer buffer,
252253
*/
253254
prstate.new_prune_xid = InvalidTransactionId;
254255
prstate.vistest = vistest;
255-
prstate.mark_unused_now = mark_unused_now;
256+
prstate.mark_unused_now = (options & HEAP_PAGE_PRUNE_MARK_UNUSED_NOW) != 0;
256257
prstate.snapshotConflictHorizon = InvalidTransactionId;
257258
prstate.nredirected = prstate.ndead = prstate.nunused = 0;
258259
prstate.ndeleted = 0;

‎src/backend/access/heap/vacuumlazy.c

Copy file name to clipboardExpand all lines: src/backend/access/heap/vacuumlazy.c
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,7 @@ lazy_scan_prune(LVRelState *vacrel,
14251425
bool all_visible,
14261426
all_frozen;
14271427
TransactionId visibility_cutoff_xid;
1428+
int prune_options = 0;
14281429
int64 fpi_before = pgWalUsage.wal_fpi;
14291430
OffsetNumber deadoffsets[MaxHeapTuplesPerPage];
14301431
HeapTupleFreeze frozen[MaxHeapTuplesPerPage];
@@ -1458,10 +1459,12 @@ lazy_scan_prune(LVRelState *vacrel,
14581459
* that were deleted from indexes.
14591460
*
14601461
* If the relation has no indexes, we can immediately mark would-be dead
1461-
* items LP_UNUSED, so mark_unused_now should be true if no indexes and
1462-
* false otherwise.
1462+
* items LP_UNUSED.
14631463
*/
1464-
heap_page_prune(rel, buf, vacrel->vistest, vacrel->nindexes == 0,
1464+
prune_options = 0;
1465+
if (vacrel->nindexes == 0)
1466+
prune_options = HEAP_PAGE_PRUNE_MARK_UNUSED_NOW;
1467+
heap_page_prune(rel, buf, vacrel->vistest, prune_options,
14651468
&presult, PRUNE_VACUUM_SCAN, &vacrel->offnum);
14661469

14671470
/*

‎src/include/access/heapam.h

Copy file name to clipboardExpand all lines: src/include/access/heapam.h
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
3737
#define HEAP_INSERT_SPECULATIVE 0x0010
3838

39+
/* "options" flag bits for heap_page_prune */
40+
#define HEAP_PAGE_PRUNE_MARK_UNUSED_NOW (1 << 0)
41+
3942
typedef struct BulkInsertStateData *BulkInsertState;
4043
struct TupleTableSlot;
4144
struct VacuumCutoffs;
@@ -331,7 +334,7 @@ struct GlobalVisState;
331334
extern void heap_page_prune_opt(Relation relation, Buffer buffer);
332335
extern void heap_page_prune(Relation relation, Buffer buffer,
333336
struct GlobalVisState *vistest,
334-
bool mark_unused_now,
337+
int options,
335338
PruneResult *presult,
336339
PruneReason reason,
337340
OffsetNumber *off_loc);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.