agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Álvaro Herrera <alvherre@kurilemu.de>
To: Andres Freund <andres@anarazel.de>
Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Zsolt Parragi <zsolt.parragi@percona.com>
Cc: Nathan Bossart <nathandbossart@gmail.com>
Subject: Re: table AM option passing
Date: Mon, 30 Mar 2026 14:08:45 +0200
Message-ID: <202603301206.adis56q72squ@alvherre.pgsql> (raw)
In-Reply-To: <202603291633.dkzj7sp3b3lq@alvherre.pgsql>
Hello,
I just pushed the part of 0001 that modifies the API of table_insert and
its sibling functions. So here 0001 adds the options bitmask to
table_update and table_delete, which is important for REPACK; and 0002
is identical as before and makes the interface (IMO) a bit more
future-proof.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Every machine is a smoke machine if you operate it wrong enough."
https://twitter.com/libseybieda/status/1541673325781196801
Attachments:
[text/x-diff] v3-0001-give-options-bitmask-to-table_delete-table_update.patch (10.2K, ../202603301206.adis56q72squ@alvherre.pgsql/2-v3-0001-give-options-bitmask-to-table_delete-table_update.patch)
download | inline diff:
From 3ca3cf3e22d7281571a9b83be71600d052659bdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Mon, 30 Mar 2026 13:27:42 +0200
Subject: [PATCH v3 1/2] give options bitmask to table_delete/table_update
---
src/backend/access/heap/heapam.c | 16 ++++++++++------
src/backend/access/heap/heapam_handler.c | 13 ++++++++-----
src/backend/access/table/tableam.c | 6 +++---
src/backend/executor/nodeModifyTable.c | 9 +++++++--
src/include/access/heapam.h | 7 ++++---
src/include/access/tableam.h | 23 +++++++++++++++--------
6 files changed, 47 insertions(+), 27 deletions(-)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 882deda6b95..1b873f55c70 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2850,8 +2850,8 @@ xmax_infomask_changed(uint16 new_infomask, uint16 old_infomask)
*/
TM_Result
heap_delete(Relation relation, const ItemPointerData *tid,
- CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, bool changingPart)
+ CommandId cid, bits32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2864,6 +2864,7 @@ heap_delete(Relation relation, const ItemPointerData *tid,
TransactionId new_xmax;
uint16 new_infomask,
new_infomask2;
+ bool changingPart = (options & TABLE_DELETE_CHANGING_PARTITION) != 0;
bool have_tuple_lock = false;
bool iscombo;
bool all_visible_cleared = false;
@@ -3278,9 +3279,11 @@ simple_heap_delete(Relation relation, const ItemPointerData *tid)
TM_FailureData tmfd;
result = heap_delete(relation, tid,
- GetCurrentCommandId(true), InvalidSnapshot,
+ GetCurrentCommandId(true),
+ 0,
+ InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, false /* changingPart */ );
+ &tmfd);
switch (result)
{
case TM_SelfModified:
@@ -3319,7 +3322,7 @@ simple_heap_delete(Relation relation, const ItemPointerData *tid)
*/
TM_Result
heap_update(Relation relation, const ItemPointerData *otid, HeapTuple newtup,
- CommandId cid, Snapshot crosscheck, bool wait,
+ CommandId cid, bits32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4573,7 +4576,8 @@ simple_heap_update(Relation relation, const ItemPointerData *otid, HeapTuple tup
LockTupleMode lockmode;
result = heap_update(relation, otid, tup,
- GetCurrentCommandId(true), InvalidSnapshot,
+ GetCurrentCommandId(true), 0,
+ InvalidSnapshot,
true /* wait for commit */ ,
&tmfd, &lockmode, update_indexes);
switch (result)
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 7c2194b152b..dd03c8c29a6 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -311,21 +311,23 @@ heapam_tuple_complete_speculative(Relation relation, TupleTableSlot *slot,
static TM_Result
heapam_tuple_delete(Relation relation, ItemPointer tid, CommandId cid,
- Snapshot snapshot, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, bool changingPart)
+ bits32 options, Snapshot snapshot, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
/*
* Currently Deleting of index tuples are handled at vacuum, in case if
* the storage itself is cleaning the dead tuples by itself, it is the
* time to call the index tuple deletion also.
*/
- return heap_delete(relation, tid, cid, crosscheck, wait, tmfd, changingPart);
+ return heap_delete(relation, tid, cid, options, crosscheck, wait,
+ tmfd);
}
static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
- CommandId cid, Snapshot snapshot, Snapshot crosscheck,
+ CommandId cid, bits32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -337,7 +339,8 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
slot->tts_tableOid = RelationGetRelid(relation);
tuple->t_tableOid = slot->tts_tableOid;
- result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
+ result = heap_update(relation, otid, tuple, cid, options,
+ crosscheck, wait,
tmfd, lockmode, update_indexes);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index dfda1af412e..50206ae782f 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -318,9 +318,9 @@ simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot)
result = table_tuple_delete(rel, tid,
GetCurrentCommandId(true),
- snapshot, InvalidSnapshot,
+ 0, snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, false /* changingPart */ );
+ &tmfd);
switch (result)
{
@@ -367,7 +367,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
result = table_tuple_update(rel, otid, slot,
GetCurrentCommandId(true),
- snapshot, InvalidSnapshot,
+ 0, snapshot, InvalidSnapshot,
true /* wait for commit */ ,
&tmfd, &lockmode, update_indexes);
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 4cd5e262e0f..9f763f756b0 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1522,14 +1522,18 @@ ExecDeleteAct(ModifyTableContext *context, ResultRelInfo *resultRelInfo,
ItemPointer tupleid, bool changingPart)
{
EState *estate = context->estate;
+ bits32 options = 0;
+
+ if (changingPart)
+ options |= TABLE_DELETE_CHANGING_PARTITION;
return table_tuple_delete(resultRelInfo->ri_RelationDesc, tupleid,
estate->es_output_cid,
+ options,
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &context->tmfd,
- changingPart);
+ &context->tmfd);
}
/*
@@ -2331,6 +2335,7 @@ lreplace:
*/
result = table_tuple_update(resultRelationDesc, tupleid, slot,
estate->es_output_cid,
+ 0,
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 53e86c0d6e1..80bcda02cb7 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -384,13 +384,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, bits32 options,
BulkInsertState bistate);
extern TM_Result heap_delete(Relation relation, const ItemPointerData *tid,
- CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, bool changingPart);
+ CommandId cid, bits32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd);
extern void heap_finish_speculative(Relation relation, const ItemPointerData *tid);
extern void heap_abort_speculative(Relation relation, const ItemPointerData *tid);
extern TM_Result heap_update(Relation relation, const ItemPointerData *otid,
HeapTuple newtup,
- CommandId cid, Snapshot crosscheck, bool wait,
+ CommandId cid, bits32 options,
+ Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 3b017e043a0..3c82b80d45d 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -269,6 +269,11 @@ typedef struct TM_IndexDeleteOp
/* Follow update chain and lock latest version of tuple */
#define TUPLE_LOCK_FLAG_FIND_LAST_VERSION (1 << 1)
+/* "options" flag bits for table_tuple_delete */
+#define TABLE_DELETE_CHANGING_PARTITION (1 << 0)
+
+/* "options" flag bits for table_tuple_update */
+/* XXX none at present */
/* Typedef for callback function for table_index_build_scan */
typedef void (*IndexBuildCallback) (Relation index,
@@ -536,17 +541,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ bits32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
- TM_FailureData *tmfd,
- bool changingPart);
+ TM_FailureData *tmfd);
/* see table_tuple_update() for reference about parameters */
TM_Result (*tuple_update) (Relation rel,
ItemPointer otid,
TupleTableSlot *slot,
CommandId cid,
+ bits32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1479,12 +1485,12 @@ table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots,
*/
static inline TM_Result
table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
- Snapshot snapshot, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, bool changingPart)
+ bits32 options, Snapshot snapshot, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
- return rel->rd_tableam->tuple_delete(rel, tid, cid,
+ return rel->rd_tableam->tuple_delete(rel, tid, cid, options,
snapshot, crosscheck,
- wait, tmfd, changingPart);
+ wait, tmfd);
}
/*
@@ -1524,12 +1530,13 @@ table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
*/
static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
- CommandId cid, Snapshot snapshot, Snapshot crosscheck,
+ CommandId cid, bits32 options,
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
- cid, snapshot, crosscheck,
+ cid, options, snapshot, crosscheck,
wait, tmfd,
lockmode, update_indexes);
}
--
2.47.3
[text/x-diff] v3-0002-Define-heap_insert-to-obey-tableam.h-option-bits-.patch (8.1K, ../202603301206.adis56q72squ@alvherre.pgsql/3-v3-0002-Define-heap_insert-to-obey-tableam.h-option-bits-.patch)
download | inline diff:
From 437e12b07d04dee3c61d5dad070084b0eebfaf54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Sun, 29 Mar 2026 23:11:42 +0200
Subject: [PATCH v3 2/2] Define heap_insert to obey tableam.h option bits
directly
Redefining the bits at the heapam.h interface is no good.
---
src/backend/access/heap/heapam.c | 18 +++++++++---------
src/backend/access/heap/hio.c | 10 +++++-----
src/backend/access/heap/rewriteheap.c | 4 ++--
src/backend/replication/logical/decode.c | 2 +-
src/include/access/heapam.h | 11 ++++++-----
5 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1b873f55c70..f257003fa65 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2137,9 +2137,9 @@ ReleaseBulkInsertStatePin(BulkInsertState bistate)
* See table_tuple_insert for comments about most of the input flags, except
* that this routine directly takes a tuple rather than a slot.
*
- * There's corresponding HEAP_INSERT_ options to all the TABLE_INSERT_
- * options, and there additionally is HEAP_INSERT_SPECULATIVE which is used to
- * implement table_tuple_insert_speculative().
+ * In addition to the TABLE_INSERT_ options, there additionally is
+ * HEAP_INSERT_SPECULATIVE which is used to implement
+ * table_tuple_insert_speculative().
*
* On return the header fields of *tup are updated to match the stored tuple;
* in particular tup->t_self receives the actual TID where the tuple was
@@ -2267,7 +2267,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
* image. (XXX We could alternatively store a pointer into the FPW).
*/
if (RelationIsLogicallyLogged(relation) &&
- !(options & HEAP_INSERT_NO_LOGICAL))
+ !(options & TABLE_INSERT_NO_LOGICAL))
{
xlrec.flags |= XLH_INSERT_CONTAINS_NEW_TUPLE;
bufflags |= REGBUF_KEEP_DATA;
@@ -2356,7 +2356,7 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid,
tup->t_data->t_infomask2 &= ~(HEAP2_XACT_MASK);
tup->t_data->t_infomask |= HEAP_XMAX_INVALID;
HeapTupleHeaderSetXmin(tup->t_data, xid);
- if (options & HEAP_INSERT_FROZEN)
+ if (options & TABLE_INSERT_FROZEN)
HeapTupleHeaderSetXminFrozen(tup->t_data);
HeapTupleHeaderSetCmin(tup->t_data, cid);
@@ -2437,7 +2437,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
int npages_used = 0;
/* currently not needed (thus unsupported) for heap_multi_insert() */
- Assert(!(options & HEAP_INSERT_NO_LOGICAL));
+ Assert(!(options & TABLE_INSERT_NO_LOGICAL));
AssertHasSnapshotForToast(relation);
@@ -2527,7 +2527,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
starting_with_empty_page = PageGetMaxOffsetNumber(page) == 0;
- if (starting_with_empty_page && (options & HEAP_INSERT_FROZEN))
+ if (starting_with_empty_page && (options & TABLE_INSERT_FROZEN))
{
all_frozen_set = true;
/* Lock the vmbuffer before entering the critical section */
@@ -2575,7 +2575,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
* page, mark it as all-frozen and update the visibility map. We're
* already holding a pin on the vmbuffer.
*/
- if (PageIsAllVisible(page) && !(options & HEAP_INSERT_FROZEN))
+ if (PageIsAllVisible(page) && !(options & TABLE_INSERT_FROZEN))
{
all_visible_cleared = true;
PageClearAllVisible(page);
@@ -2643,7 +2643,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
/*
* We don't have to worry about including a conflict xid in the
- * WAL record, as HEAP_INSERT_FROZEN intentionally violates
+ * WAL record, as TABLE_INSERT_FROZEN intentionally violates
* visibility rules.
*/
if (all_frozen_set)
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c
index 1097f44a74e..146c8cc4a68 100644
--- a/src/backend/access/heap/hio.c
+++ b/src/backend/access/heap/hio.c
@@ -469,12 +469,12 @@ RelationAddBlocks(Relation relation, BulkInsertState bistate,
* which is indicated by these arguments not being InvalidBuffer on entry.
*
* We normally use FSM to help us find free space. However,
- * if HEAP_INSERT_SKIP_FSM is specified, we just append a new empty page to
+ * if TABLE_INSERT_SKIP_FSM is specified, we just append a new empty page to
* the end of the relation if the tuple won't fit on the current target page.
* This can save some cycles when we know the relation is new and doesn't
* contain useful amounts of free space.
*
- * HEAP_INSERT_SKIP_FSM is also useful for non-WAL-logged additions to a
+ * TABLE_INSERT_SKIP_FSM is also useful for non-WAL-logged additions to a
* relation, if the caller holds exclusive lock and is careful to invalidate
* relation's smgr_targblock before the first insertion --- that ensures that
* all insertions will occur into newly added pages and not be intermixed
@@ -503,7 +503,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
Buffer *vmbuffer, Buffer *vmbuffer_other,
int num_pages)
{
- bool use_fsm = !(options & HEAP_INSERT_SKIP_FSM);
+ bool use_fsm = !(options & TABLE_INSERT_SKIP_FSM);
Buffer buffer = InvalidBuffer;
Page page;
Size nearlyEmptyFreeSpace,
@@ -621,7 +621,7 @@ loop:
/*
* If the page is empty, pin vmbuffer to set all_frozen bit later.
*/
- if ((options & HEAP_INSERT_FROZEN) &&
+ if ((options & TABLE_INSERT_FROZEN) &&
(PageGetMaxOffsetNumber(BufferGetPage(buffer)) == 0))
visibilitymap_pin(relation, targetBlock, vmbuffer);
@@ -774,7 +774,7 @@ loop:
* do IO while the buffer is locked, so we unlock the page first if IO is
* needed (necessitating checks below).
*/
- if (options & HEAP_INSERT_FROZEN)
+ if (options & TABLE_INSERT_FROZEN)
{
Assert(PageGetMaxOffsetNumber(page) == 0);
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 6b19ac3030d..b21dd6bb26b 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -618,14 +618,14 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
}
else if (HeapTupleHasExternal(tup) || tup->t_len > TOAST_TUPLE_THRESHOLD)
{
- int options = HEAP_INSERT_SKIP_FSM;
+ int options = TABLE_INSERT_SKIP_FSM;
/*
* While rewriting the heap for VACUUM FULL / CLUSTER, make sure data
* for the TOAST table are not logically decoded. The main heap is
* WAL-logged as XLOG FPI records, which are not logically decoded.
*/
- options |= HEAP_INSERT_NO_LOGICAL;
+ options |= TABLE_INSERT_NO_LOGICAL;
heaptup = heap_toast_insert_or_update(state->rs_new_rel, tup, NULL,
options);
diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c
index 3c027bcb2f7..d80a26ce88e 100644
--- a/src/backend/replication/logical/decode.c
+++ b/src/backend/replication/logical/decode.c
@@ -898,7 +898,7 @@ DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
/*
* Ignore insert records without new tuples (this does happen when
- * raw_heap_insert marks the TOAST record as HEAP_INSERT_NO_LOGICAL).
+ * raw_heap_insert marks the TOAST record as TABLE_INSERT_NO_LOGICAL).
*/
if (!(xlrec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE))
return;
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 80bcda02cb7..97ef403ee43 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -33,11 +33,12 @@
#include "utils/snapshot.h"
-/* "options" flag bits for heap_insert */
-#define HEAP_INSERT_SKIP_FSM TABLE_INSERT_SKIP_FSM
-#define HEAP_INSERT_FROZEN TABLE_INSERT_FROZEN
-#define HEAP_INSERT_NO_LOGICAL TABLE_INSERT_NO_LOGICAL
-#define HEAP_INSERT_SPECULATIVE 0x0010
+/*
+ * "options" flag bits for heap_insert. That routine also obeys bits defined
+ * for table_tuple_insert; see tableam.h. We define these starting from the
+ * opposite end of the options word.
+ */
+#define HEAP_INSERT_SPECULATIVE (1 << 31)
/* "options" flag bits for heap_page_prune_and_freeze */
#define HEAP_PAGE_PRUNE_MARK_UNUSED_NOW (1 << 0)
--
2.47.3
view thread (17+ messages) latest in thread
Message-ID: <202603301206.adis56q72squ@alvherre.pgsql>
Permalink: ../202603301206.adis56q72squ@alvherre.pgsql/
Also on: postgresql.org/message-id/202603301206.adis56q72squ@alvherre.pgsql
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvherre@kurilemu.de, andres@anarazel.de, pgsql-hackers@lists.postgresql.org, zsolt.parragi@percona.com, nathandbossart@gmail.com
Subject: Re: table AM option passing
In-Reply-To: <202603301206.adis56q72squ@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox