agora inbox for [email protected]
help / color / mirror / Atom feedRe: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
989+ messages / 3 participants
[nested] [flat]
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-15 09:19 Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-15 09:19 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; pgsql-hackers
On 2020/07/17 21:02, Bharath Rupireddy wrote:
>>
>> On Tue, Jul 14, 2020 at 6:13 PM Ashutosh Bapat
>> <[email protected]> wrote:
>>>
>>> Has this been added to CF, possibly next CF?
>>>
>>
>> I have not added yet. Request to get it done in this CF, as the final
>> patch for review(v3 patch) is ready and shared. We can target it to
>> the next CF if there are major issues with the patch.
>>
>
> I added this feature to the next CF - https://commitfest.postgresql.org/29/2651/
Thanks for the patch! Here are some comments from me.
+ PQreset(entry->conn);
Isn't using PQreset() to reconnect to the foreign server unsafe?
When new connection is established, some SET commands seem
to need to be issued like configure_remote_session() does.
But PQreset() doesn't do that at all.
Originally when GetConnection() establishes new connection,
it resets all transient state fields, to be sure all are clean (as the
comment says). With the patch, even when reconnecting
the remote server, shouldn't we do the same, for safe?
+ PGresult *res = NULL;
+ res = PQgetResult(entry->conn);
+ PQclear(res);
Are these really necessary? I was just thinking that's not because
pgfdw_get_result() and pgfdw_report_error() seem to do that
already in do_sql_command().
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
Even when there is no cached connection and new connection is made,
then if begin_remote_xact() reports an error, another new connection
tries to be made again. This behavior looks a bit strange.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-17 06:44 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-09-17 06:44 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
Thanks for the review comments. I will post a new patch soon
addressing all the comments.
On Tue, Sep 15, 2020 at 2:49 PM Fujii Masao <[email protected]> wrote:
>
> + PQreset(entry->conn);
>
> Isn't using PQreset() to reconnect to the foreign server unsafe?
> When new connection is established, some SET commands seem
> to need to be issued like configure_remote_session() does.
> But PQreset() doesn't do that at all.
>
This is a good catch. Thanks, I missed this point. Indeed we need to
set the session params. We can do this in two ways: 1. use
configure_remote_session() after PQreset(). 2. use connect_pg_server()
instead of PQreset() and configure_remote_session(). One problem I see
with the 2nd way is that we will be doing the checks that are being
performed in connect_pg_server() twice, which we would have done for
the first time before retrying. The required parameters such as
keywords, values, are still in entry->conn structure from the first
attempt, which can safely be used by PQreset(). So, I will go with the
1st way. Thoughts?
>
> Originally when GetConnection() establishes new connection,
> it resets all transient state fields, to be sure all are clean (as the
> comment says). With the patch, even when reconnecting
> the remote server, shouldn't we do the same, for safe?
>
I guess there is no need for us to reset all the transient state
before we do begin_remote_xact() in the 2nd attempt. We retry the
connection only when entry->xact_depth <= 0 i.e. beginning of the
remote txn and the begin_remote_xact() doesn't modify any transient
state if entry->xact_depth <= 0, except for entry->changing_xact_state
= true; all other transient state is intact in entry structure. In the
error case, we will not reach the code after do_sql_command in
begin_remote_xact(). If needed, we can only set
entry->changing_xact_state to false which is set to true before
do_sql_command().
entry->changing_xact_state = true;
do_sql_command(entry->conn, sql);
entry->xact_depth = 1;
entry->changing_xact_state = false;
>
> + PGresult *res = NULL;
> + res = PQgetResult(entry->conn);
> + PQclear(res);
> Are these really necessary? I was just thinking that's not because
> pgfdw_get_result() and pgfdw_report_error() seem to do that
> already in do_sql_command().
>
If an error occurs in the first attempt, we return from
pgfdw_get_result()'s if (!PQconsumeInput(conn)) to the catch block we
added and pgfdw_report_error() will never get called. And the below
part of the code is reached only in scenarios as mentioned in the
comments. Removing this might have problems if we receive errors other
than CONNECTION_BAD or for subtxns. We could clear if any result and
just rethrow the error upstream. I think no problem having this code
here.
else
{
/*
* We are here, due to either some error other than CONNECTION_BAD
* occurred or connection may have broken during start of a
* subtransacation. Just, clear off any result, try rethrowing the
* error, so that it will be caught appropriately.
*/
PGresult *res = NULL;
res = PQgetResult(entry->conn);
PQclear(res);
PG_RE_THROW();
}
>
> + /* Start a new transaction or subtransaction if needed. */
> + begin_remote_xact(entry);
>
> Even when there is no cached connection and new connection is made,
> then if begin_remote_xact() reports an error, another new connection
> tries to be made again. This behavior looks a bit strange.
>
When there is no cached connection, we try to acquire one, if we
can't, then no error will be thrown to the user, just we retry one
more time. If we get in the 2nd attempt, fine, if not, we will throw
the error to the user. Assume in the 1st attempt the remote server is
unreachable, we may hope to connect in the 2nd attempt. I think there
is no problem here.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-17 16:50 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-17 16:50 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/09/17 15:44, Bharath Rupireddy wrote:
> Thanks for the review comments. I will post a new patch soon
> addressing all the comments.
Thanks a lot!
>
> On Tue, Sep 15, 2020 at 2:49 PM Fujii Masao <[email protected]> wrote:
>>
>> + PQreset(entry->conn);
>>
>> Isn't using PQreset() to reconnect to the foreign server unsafe?
>> When new connection is established, some SET commands seem
>> to need to be issued like configure_remote_session() does.
>> But PQreset() doesn't do that at all.
>>
>
> This is a good catch. Thanks, I missed this point. Indeed we need to
> set the session params. We can do this in two ways: 1. use
> configure_remote_session() after PQreset(). 2. use connect_pg_server()
> instead of PQreset() and configure_remote_session(). One problem I see
> with the 2nd way is that we will be doing the checks that are being
> performed in connect_pg_server() twice, which we would have done for
> the first time before retrying. The required parameters such as
> keywords, values, are still in entry->conn structure from the first
> attempt, which can safely be used by PQreset(). So, I will go with the
> 1st way. Thoughts?
In 1st way, you may also need to call ReleaseExternalFD() when new connection fails
to be made, as connect_pg_server() does. Also we need to check that
non-superuser has used password to make new connection,
as connect_pg_server() does? I'm concerned about the case where
pg_hba.conf is changed accidentally so that no password is necessary
at the remote server and the existing connection is terminated. In this case,
if we connect to the local server as non-superuser, connection to
the remote server should fail because the remote server doesn't
require password. But with your patch, we can successfully reconnect
to the remote server.
Therefore I like 2nd option. Also maybe disconnect_ps_server() needs to
be called before that. I'm not sure how much useful 1st option is.
>
>>
>> Originally when GetConnection() establishes new connection,
>> it resets all transient state fields, to be sure all are clean (as the
>> comment says). With the patch, even when reconnecting
>> the remote server, shouldn't we do the same, for safe?
>>
>
> I guess there is no need for us to reset all the transient state
> before we do begin_remote_xact() in the 2nd attempt. We retry the
> connection only when entry->xact_depth <= 0 i.e. beginning of the
> remote txn and the begin_remote_xact() doesn't modify any transient
> state if entry->xact_depth <= 0, except for entry->changing_xact_state
> = true; all other transient state is intact in entry structure. In the
> error case, we will not reach the code after do_sql_command in
> begin_remote_xact(). If needed, we can only set
> entry->changing_xact_state to false which is set to true before
> do_sql_command().
What if 2nd attempt happens with have_prep_stmt=true? I'm not sure
if this case really happens, though. But if that can, it's strange to start
new connection with have_prep_stmt=true even when the caller of
GetConnection() doesn't intend to create any prepared statements.
I think it's safer to do 2nd attempt in the same way as 1st one. Maybe
we can simplify the code by making them into common code block
or function.
>
> entry->changing_xact_state = true;
> do_sql_command(entry->conn, sql);
> entry->xact_depth = 1;
> entry->changing_xact_state = false;
>
>>
>> + PGresult *res = NULL;
>> + res = PQgetResult(entry->conn);
>> + PQclear(res);
>> Are these really necessary? I was just thinking that's not because
>> pgfdw_get_result() and pgfdw_report_error() seem to do that
>> already in do_sql_command().
>>
>
> If an error occurs in the first attempt, we return from
> pgfdw_get_result()'s if (!PQconsumeInput(conn)) to the catch block we
> added and pgfdw_report_error() will never get called. And the below
> part of the code is reached only in scenarios as mentioned in the
> comments. Removing this might have problems if we receive errors other
> than CONNECTION_BAD or for subtxns. We could clear if any result and
> just rethrow the error upstream. I think no problem having this code
> here.
But the orignal code works without this?
Or you mean that the original code has the bug?
>
> else
> {
> /*
> * We are here, due to either some error other than CONNECTION_BAD
> * occurred or connection may have broken during start of a
> * subtransacation. Just, clear off any result, try rethrowing the
> * error, so that it will be caught appropriately.
> */
> PGresult *res = NULL;
> res = PQgetResult(entry->conn);
> PQclear(res);
> PG_RE_THROW();
> }
>
>>
>> + /* Start a new transaction or subtransaction if needed. */
>> + begin_remote_xact(entry);
>>
>> Even when there is no cached connection and new connection is made,
>> then if begin_remote_xact() reports an error, another new connection
>> tries to be made again. This behavior looks a bit strange.
>>
>
> When there is no cached connection, we try to acquire one, if we
> can't, then no error will be thrown to the user, just we retry one
> more time. If we get in the 2nd attempt, fine, if not, we will throw
> the error to the user. Assume in the 1st attempt the remote server is
> unreachable, we may hope to connect in the 2nd attempt. I think there
> is no problem here.
>
>
> With Regards,
> Bharath Rupireddy.
> EnterpriseDB: http://www.enterprisedb.com
>
>
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-21 03:44 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-09-21 03:44 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Thu, Sep 17, 2020 at 10:20 PM Fujii Masao <[email protected]>
wrote:
>
> In 1st way, you may also need to call ReleaseExternalFD() when new
connection fails
> to be made, as connect_pg_server() does. Also we need to check that
> non-superuser has used password to make new connection,
> as connect_pg_server() does? I'm concerned about the case where
> pg_hba.conf is changed accidentally so that no password is necessary
> at the remote server and the existing connection is terminated. In this
case,
> if we connect to the local server as non-superuser, connection to
> the remote server should fail because the remote server doesn't
> require password. But with your patch, we can successfully reconnect
> to the remote server.
>
> Therefore I like 2nd option. Also maybe disconnect_ps_server() needs to
> be called before that. I'm not sure how much useful 1st option is.
>
Thanks. Above points look sensible. +1 for the 2nd option i.e. instead of
PQreset(entry->conn);, let's try to disconnect_pg_server() and
connect_pg_server().
>
> What if 2nd attempt happens with have_prep_stmt=true? I'm not sure
> if this case really happens, though. But if that can, it's strange to
start
> new connection with have_prep_stmt=true even when the caller of
> GetConnection() doesn't intend to create any prepared statements.
>
> I think it's safer to do 2nd attempt in the same way as 1st one. Maybe
> we can simplify the code by making them into common code block
> or function.
>
I don't think the have_prep_stmt will be set by the time we make 2nd
attempt because entry->have_prep_stmt |= will_prep_stmt; gets hit only
after we are successful in either 1st attempt or 2nd attempt. I think we
don't need to set all transient state. No other transient state except
changing_xact_state changes from 1st attempt to 2nd attempt(see below), so
let's set only entry->changing_xact_state to false before 2nd attempt.
1st attempt:
(gdb) p *entry
$3 = {key = 16389, conn = 0x55a896199990, xact_depth = 0, have_prep_stmt =
false,
have_error = false, changing_xact_state = false, invalidated = false,
server_hashvalue = 3905865521, mapping_hashvalue = 2617776010}
2nd attempt i.e. in retry block:
(gdb) p *entry
$4 = {key = 16389, conn = 0x55a896199990, xact_depth = 0, have_prep_stmt =
false,
have_error = false, changing_xact_state = true, invalidated = false,
server_hashvalue = 3905865521, mapping_hashvalue = 2617776010}
>>
> > If an error occurs in the first attempt, we return from
> > pgfdw_get_result()'s if (!PQconsumeInput(conn)) to the catch block we
> > added and pgfdw_report_error() will never get called. And the below
> > part of the code is reached only in scenarios as mentioned in the
> > comments. Removing this might have problems if we receive errors other
> > than CONNECTION_BAD or for subtxns. We could clear if any result and
> > just rethrow the error upstream. I think no problem having this code
> > here.
>
> But the orignal code works without this?
> Or you mean that the original code has the bug?
>
There's no bug in the original code. Sorry, I was wrong in saying
pgfdw_report_error() will never get called with this patch. Indeed it gets
called even when 1's attempt connection is failed. Since we added an extra
try-catch block, we will not be throwing the error to the user, instead we
make a 2nd attempt from the catch block.
I'm okay to remove below part of the code
> >> + PGresult *res = NULL;
> >> + res = PQgetResult(entry->conn);
> >> + PQclear(res);
> >> Are these really necessary? I was just thinking that's not because
> >> pgfdw_get_result() and pgfdw_report_error() seem to do that
> >> already in do_sql_command().
Please let me know if okay with the above agreed points, I will work on the
new patch.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-23 14:49 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-23 14:49 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/09/21 12:44, Bharath Rupireddy wrote:
> On Thu, Sep 17, 2020 at 10:20 PM Fujii Masao <[email protected] <mailto:[email protected]>> wrote:
> >
> > In 1st way, you may also need to call ReleaseExternalFD() when new connection fails
> > to be made, as connect_pg_server() does. Also we need to check that
> > non-superuser has used password to make new connection,
> > as connect_pg_server() does? I'm concerned about the case where
> > pg_hba.conf is changed accidentally so that no password is necessary
> > at the remote server and the existing connection is terminated. In this case,
> > if we connect to the local server as non-superuser, connection to
> > the remote server should fail because the remote server doesn't
> > require password. But with your patch, we can successfully reconnect
> > to the remote server.
> >
> > Therefore I like 2nd option. Also maybe disconnect_ps_server() needs to
> > be called before that. I'm not sure how much useful 1st option is.
> >
>
> Thanks. Above points look sensible. +1 for the 2nd option i.e. instead of PQreset(entry->conn);, let's try to disconnect_pg_server() and connect_pg_server().
>
> >
> > What if 2nd attempt happens with have_prep_stmt=true? I'm not sure
> > if this case really happens, though. But if that can, it's strange to start
> > new connection with have_prep_stmt=true even when the caller of
> > GetConnection() doesn't intend to create any prepared statements.
> >
> > I think it's safer to do 2nd attempt in the same way as 1st one. Maybe
> > we can simplify the code by making them into common code block
> > or function.
> >
>
> I don't think the have_prep_stmt will be set by the time we make 2nd attempt because entry->have_prep_stmt |= will_prep_stmt; gets hit only after we are successful in either 1st attempt or 2nd attempt. I think we don't need to set all transient state. No other transient state except changing_xact_state changes from 1st attempt to 2nd attempt(see below), so let's set only entry->changing_xact_state to false before 2nd attempt.
>
> 1st attempt:
> (gdb) p *entry
> $3 = {key = 16389, conn = 0x55a896199990, xact_depth = 0, have_prep_stmt = false,
> have_error = false, changing_xact_state = false, invalidated = false,
> server_hashvalue = 3905865521, mapping_hashvalue = 2617776010}
>
> 2nd attempt i.e. in retry block:
> (gdb) p *entry
> $4 = {key = 16389, conn = 0x55a896199990, xact_depth = 0, have_prep_stmt = false,
> have_error = false, changing_xact_state = true, invalidated = false,
> server_hashvalue = 3905865521, mapping_hashvalue = 2617776010}
>
> >>
> > > If an error occurs in the first attempt, we return from
> > > pgfdw_get_result()'s if (!PQconsumeInput(conn)) to the catch block we
> > > added and pgfdw_report_error() will never get called. And the below
> > > part of the code is reached only in scenarios as mentioned in the
> > > comments. Removing this might have problems if we receive errors other
> > > than CONNECTION_BAD or for subtxns. We could clear if any result and
> > > just rethrow the error upstream. I think no problem having this code
> > > here.
> >
> > But the orignal code works without this?
> > Or you mean that the original code has the bug?
> >
>
> There's no bug in the original code. Sorry, I was wrong in saying pgfdw_report_error() will never get called with this patch. Indeed it gets called even when 1's attempt connection is failed. Since we added an extra try-catch block, we will not be throwing the error to the user, instead we make a 2nd attempt from the catch block.
>
> I'm okay to remove below part of the code
>
> > >> + PGresult *res = NULL;
> > >> + res = PQgetResult(entry->conn);
> > >> + PQclear(res);
> > >> Are these really necessary? I was just thinking that's not because
> > >> pgfdw_get_result() and pgfdw_report_error() seem to do that
> > >> already in do_sql_command().
>
> Please let me know if okay with the above agreed points, I will work on the new patch.
Yes, please work on the patch! Thanks! I may revisit the above points later, though ;)
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-25 04:56 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-09-25 04:56 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Wed, Sep 23, 2020 at 8:19 PM Fujii Masao <[email protected]> wrote:
>
> > Please let me know if okay with the above agreed points, I will work on the new patch.
>
> Yes, please work on the patch! Thanks! I may revisit the above points later, though ;)
>
Thanks, attaching v4 patch. Please consider this for further review.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/octet-stream] v4-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (7.8K, ../../CALj2ACXDw5o_TufkkVAFivMTa1LL1e=nVTkvoo1uij9-THk2uw@mail.gmail.com/2-v4-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
From cc911b79ed1bbcf1a330977b69cc4fe291c2a3a0 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Fri, 25 Sep 2020 10:11:59 +0530
Subject: [PATCH] Retry Cached Remote Connections For postgres_fdw
Remote connections are cached for postgres_fdw in the local
backend. There are high chances that the remote backend may
not be available i.e. it can get killed, the subsequent foreign
queries from local backend/session that use cached connection
will fail as the remote backend would have become unavailable.
This patch proposes a retry mechanism. Local backend/session
uses cached connection and if it receives connection bad error,
it deletes the cached entry and retry to get a new connection.
This retry happens only at the start of remote xact.
---
contrib/postgres_fdw/connection.c | 62 ++++++++++++++++---
.../postgres_fdw/expected/postgres_fdw.out | 55 ++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 31 ++++++++++
3 files changed, 140 insertions(+), 8 deletions(-)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..ab8d505d64 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -170,12 +170,6 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +200,61 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote
+ * xact is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ }
+ PG_CATCH();
+ {
+ if (entry->conn &&
+ PQstatus(entry->conn) == CONNECTION_BAD &&
+ entry->xact_depth <= 0)
+ {
+ /* server object will be used for log messages. */
+ ForeignServer *server = GetForeignServer(user->serverid);
+
+ /*
+ * xact_depth <=0, which means we are retrying only at
+ * the beginning of remote xact. This is sensible,
+ * since we can't retry in the middle of a remote xact.
+ */
+ elog(DEBUG3, "postgres_fdw connection %p to the server \"%s\" is broken, retrying to connect",
+ entry->conn, server->servername);
+
+ disconnect_pg_server(entry);
+
+ /*
+ * Reset the transient state fields that may have been
+ * modified in the first attempt.
+ */
+ entry->changing_xact_state = false;
+
+ entry->conn = connect_pg_server(server, user);
+
+ if (entry->conn && PQstatus(entry->conn) == CONNECTION_OK)
+ elog(DEBUG3, "postgres_fdw connection retry to the server \"%s\" is successful",
+ server->servername);
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
+ errmsg("could not connect to server \"%s\"",
+ server->servername),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn)))));
+
+ /* Retry starting a new transaction. */
+ begin_remote_xact(entry);
+ }
+ else
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..d72b11a3ac 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,58 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+SELECT * FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..7a1b4c78bd 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,34 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+SELECT * FROM ft1 LIMIT 1; -- should fail
+COMMIT;
--
2.25.1
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-25 09:51 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-25 09:51 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/09/25 13:56, Bharath Rupireddy wrote:
> On Wed, Sep 23, 2020 at 8:19 PM Fujii Masao <[email protected]> wrote:
>>
>>> Please let me know if okay with the above agreed points, I will work on the new patch.
>>
>> Yes, please work on the patch! Thanks! I may revisit the above points later, though ;)
>>
>
> Thanks, attaching v4 patch. Please consider this for further review.
Thanks for updating the patch!
In the orignal code, disconnect_pg_server() is called when invalidation
occurs and connect_pg_server() is called when no valid connection exists.
I think that we can simplify the code by merging the connection-retry
code into them, like the attached very WIP patch (based on yours) does.
Basically I'd like to avoid duplicating disconnect_pg_server(),
connect_pg_server() and begin_remote_xact() if possible. Thought?
Your patch adds several codes into PG_CATCH() section, but it's better
to keep that section simple enough (as the source comment for
PG_CATCH() explains). So what about moving some codes out of PG_CATCH()
section?
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
+ errmsg("could not connect to server \"%s\"",
+ server->servername),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn)))));
The above is not necessary? If this error occurs, connect_pg_server()
reports an error, before the above code is reached. Right?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..9f76261d99 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ bool need_reset_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+reset:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also if previous attempt to start
+ * new remote transaction failed on the cached connection, disconnect
+ * it to reestablish new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated && entry->xact_depth == 0) ||
+ need_reset_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (need_reset_conn)
+ elog(DEBUG3, "closing connection %p to reestablish connection",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,31 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote
+ * xact is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ need_reset_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ need_reset_conn)
+ PG_RE_THROW();
+ need_reset_conn = true;
+ }
+ PG_END_TRY();
+
+ if (need_reset_conn)
+ goto reset;
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..d72b11a3ac 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,58 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+SELECT * FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..7a1b4c78bd 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,34 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+SELECT * FROM ft1 LIMIT 1; -- should fail
+COMMIT;
Attachments:
[text/plain] v4-Retry-Cached-Remote-Connections-For-postgres_fdw_fujii.patch (6.8K, ../../[email protected]/2-v4-Retry-Cached-Remote-Connections-For-postgres_fdw_fujii.patch)
download | inline diff:
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..9f76261d99 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ bool need_reset_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+reset:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also if previous attempt to start
+ * new remote transaction failed on the cached connection, disconnect
+ * it to reestablish new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated && entry->xact_depth == 0) ||
+ need_reset_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (need_reset_conn)
+ elog(DEBUG3, "closing connection %p to reestablish connection",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,31 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote
+ * xact is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ need_reset_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ need_reset_conn)
+ PG_RE_THROW();
+ need_reset_conn = true;
+ }
+ PG_END_TRY();
+
+ if (need_reset_conn)
+ goto reset;
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..d72b11a3ac 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,58 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+SELECT * FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..7a1b4c78bd 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,34 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+SELECT * FROM ft1 LIMIT 1; -- should fail
+COMMIT;
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-25 12:19 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-09-25 12:19 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Fri, Sep 25, 2020 at 3:21 PM Fujii Masao <[email protected]>
wrote:
>
> I think that we can simplify the code by merging the connection-retry
> code into them, like the attached very WIP patch (based on yours) does.
>
+1.
>
> + else
> + ereport(ERROR,
> +
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
> + errmsg("could not connect to
server \"%s\"",
> +
server->servername),
> + errdetail_internal("%s",
pchomp(PQerrorMessage(entry->conn)))));
>
> The above is not necessary? If this error occurs, connect_pg_server()
> reports an error, before the above code is reached. Right?
>
Removed.
Thanks for the comments.
I think we need to have a volatile qualifier for need_reset_conn, because
of the sigsetjmp.
Instead of "need_reset_conn", "retry_conn" would be more meaningful and
also instead of goto label name "reset;", "retry:".
I changed "closing connection %p to reestablish connection" to "closing
connection %p to reestablish a new one"
I also adjusted the comments to be under the 80char limit.
I feel, when we are about to close an existing connection and reestablish a
new connection, it will be good to have a debug3 message saying that we
"could not connect to postgres_fdw connection %p"[1].
Attaching v5 patch that has the above changes. Both make check and make
check-world regression tests passes. Please review.
[1] This would tell the user that we are not able to connect to the
connection.
postgres=# SELECT * FROM foreign_tbl;
DEBUG: starting remote transaction on connection 0x55ab0e416830
DEBUG: could not connect to postgres_fdw connection 0x55ab0e416830
DEBUG: closing connection 0x55ab0e416830 to reestablish a new one
DEBUG: new postgres_fdw connection 0x55ab0e416830 for server
"foreign_server" (user mapping oid 16407, userid 10)
DEBUG: starting remote transaction on connection 0x55ab0e416830
DEBUG: closing remote transaction on connection 0x55ab0e416830
a1 | b1
-----+-----
100 | 200
Without the above message, it would look like we are starting remote txn,
and closing connection without any reason.
postgres=# SELECT * FROM foreign_tbl;
DEBUG: starting remote transaction on connection 0x55ab0e4c0d50
DEBUG: closing connection 0x55ab0e4c0d50 to reestablish a new one
DEBUG: new postgres_fdw connection 0x55ab0e4c0d50 for server
"foreign_server" (user mapping oid 16389, userid 10)
DEBUG: starting remote transaction on connection 0x55ab0e4c0d50
DEBUG: closing remote transaction on connection 0x55ab0e4c0d50
a1 | b1
-----+-----
100 | 200
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/octet-stream] v5-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (8.0K, ../../CALj2ACVOw5jDLdAEmfqEa3r-PMQYhu-8Z3MsbHP3w8aV97h2aw@mail.gmail.com/3-v5-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
From 0df20a1cf6d084f8bf3d8768d29893416fd3c83e Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Fri, 25 Sep 2020 17:30:35 +0530
Subject: [PATCH v5] Retry Cached Remote Connections For postgres_fdw
Remote connections are cached for postgres_fdw in the local
backend. There are high chances that the remote backend may
not be available i.e. it can get killed, the subsequent foreign
queries from local backend/session that use cached connection
will fail as the remote backend would have become unavailable.
This patch proposes a retry mechanism. Local backend/session
uses cached connection and if it receives connection bad error,
it deletes the cached entry and retry to get a new connection.
This retry happens only at the start of remote xact.
---
contrib/postgres_fdw/connection.c | 54 +++++++++++++-----
.../postgres_fdw/expected/postgres_fdw.out | 55 +++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 31 +++++++++++
3 files changed, 127 insertions(+), 13 deletions(-)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..435cf656f7 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
- * If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * If the connection needs to be remade due to invalidation, disconnect
+ * as soon as we're out of all transactions. Also, if previous attempt
+ * to start new remote transaction failed on the cached connection,
+ * disconnect it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,34 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote
+ * xact is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ elog(DEBUG3, "could not connect to postgres_fdw connection %p", entry->conn);
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..d72b11a3ac 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,58 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+----+----+----+----+------------+----
+ 1111 | 2 | | | | | ft1 |
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+SELECT * FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..7a1b4c78bd 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,34 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT * FROM ft1 LIMIT 1;
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT * FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+SELECT * FROM ft1 LIMIT 1; -- should fail
+COMMIT;
--
2.25.1
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-29 14:00 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-29 14:00 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/09/25 21:19, Bharath Rupireddy wrote:
> On Fri, Sep 25, 2020 at 3:21 PM Fujii Masao <[email protected] <mailto:[email protected]>> wrote:
> >
> > I think that we can simplify the code by merging the connection-retry
> > code into them, like the attached very WIP patch (based on yours) does.
> >
>
> +1.
>
> >
> > + else
> > + ereport(ERROR,
> > + (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
> > + errmsg("could not connect to server \"%s\"",
> > + server->servername),
> > + errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn)))));
> >
> > The above is not necessary? If this error occurs, connect_pg_server()
> > reports an error, before the above code is reached. Right?
> >
>
> Removed.
>
> Thanks for the comments.
>
> I think we need to have a volatile qualifier for need_reset_conn, because of the sigsetjmp.
Yes.
> Instead of "need_reset_conn", "retry_conn" would be more meaningful and also instead of goto label name "reset;", "retry:".
Sounds good.
> I changed "closing connection %p to reestablish connection" to "closing connection %p to reestablish a new one"
OK.
> I also adjusted the comments to be under the 80char limit.
> I feel, when we are about to close an existing connection and reestablish a new connection, it will be good to have a debug3 message saying that we "could not connect to postgres_fdw connection %p"[1].
+1 to add debug3 message there. But this message doesn't seem to
match with what the error actually happened. What about something like
"could not start remote transaction on connection %p", instead?
Also maybe it's better to append PQerrorMessage(entry->conn)?
>
> Attaching v5 patch that has the above changes. Both make check and make check-world regression tests passes. Please review.
Thanks for updating the patch!
+-- Generate a connection to remote. Local backend will cache it.
+SELECT * FROM ft1 LIMIT 1;
The result of this query would not be stable. Probably you need to,
for example, add ORDER BY or replace * with 1, etc.
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
Isn't this test fragile because there is no gurantee that the target backend
has exited just after calling pg_terminate_backend()?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-29 15:50 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-09-29 15:50 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
Thanks for the comments.
On Tue, Sep 29, 2020 at 7:30 PM Fujii Masao <[email protected]> wrote:
>
> +1 to add debug3 message there. But this message doesn't seem to
> match with what the error actually happened. What about something like
> "could not start remote transaction on connection %p", instead?
>
Looks better. Changed.
>
> Also maybe it's better to append PQerrorMessage(entry->conn)?
>
Added. Now the log looks like [1].
>
> +-- Generate a connection to remote. Local backend will cache it.
> +SELECT * FROM ft1 LIMIT 1;
>
> The result of this query would not be stable. Probably you need to,
> for example, add ORDER BY or replace * with 1, etc.
>
Changed to SELECT 1 FROM ft1 LIMIT 1;
>
> +-- Retrieve pid of remote backend with application name fdw_retry_check
> +-- and kill it intentionally here. Note that, local backend still has
> +-- the remote connection/backend info in it's cache.
> +SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
> +backend_type = 'client backend' AND application_name = 'fdw_retry_check';
>
> Isn't this test fragile because there is no gurantee that the target backend
> has exited just after calling pg_terminate_backend()?
>
I think this is okay, because pg_terminate_backend() sends SIGTERM to
the backend, and upon receiving SIGTERM the signal handler die() will
be called and since there is no query being executed on the backend by
the time SIGTERM is received, it will exit immediately. Thoughts?
pqsignal(SIGTERM, die); /* cancel current query and exit */
And also, pg_terminate_backend() returns true in case the backend is
killed successfully, otherwise it returns false. PG_RETURN_BOOL(r
== SIGNAL_BACKEND_SUCCESS);
Attaching v6 patch, please review it further.
[1]
DEBUG: starting remote transaction on connection 0x55cd393a66e0
DEBUG: could not start remote transaction on connection 0x55cd393a66e0
DETAIL: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
DEBUG: closing connection 0x55cd393a66e0 to reestablish a new one
DEBUG: new postgres_fdw connection 0x55cd393a66e0 for server
"foreign_server" (user mapping oid 16398, userid 10)
DEBUG: starting remote transaction on connection 0x55cd393a66e0
DEBUG: closing remote transaction on connection 0x55cd393a66e0
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/octet-stream] v6-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (7.8K, ../../CALj2ACXb85AHaUg=qZ0sBNR2nye2Q2NuYV14kBL1oXZud=tOJg@mail.gmail.com/2-v6-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
From 6c5545c4deb1783a09ecb869a9b189add325099e Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Tue, 29 Sep 2020 21:16:30 +0530
Subject: [PATCH v6] Retry Cached Remote Connections For postgres_fdw
Remote connections are cached for postgres_fdw in the local
backend. There are high chances that the remote backend may
not be available i.e. it can get killed, the subsequent foreign
queries from local backend/session that use cached connection
will fail as the remote backend would have become unavailable.
This patch proposes a retry mechanism. Local backend/session
uses cached connection and if it receives connection bad error,
it deletes the cached entry and retry to get a new connection.
This retry happens only at the start of remote xact.
---
contrib/postgres_fdw/connection.c | 57 ++++++++++++++-----
.../postgres_fdw/expected/postgres_fdw.out | 55 ++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 31 ++++++++++
3 files changed, 130 insertions(+), 13 deletions(-)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..16eca788ac 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
- * If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * If the connection needs to be remade due to invalidation, disconnect
+ * as soon as we're out of all transactions. Also, if previous attempt
+ * to start new remote transaction failed on the cached connection,
+ * disconnect it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,37 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote
+ * xact is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ ereport(DEBUG3,
+ (errmsg("could not start remote transaction on connection %p",
+ entry->conn)),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..e16a5b7e04 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,58 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- Generate a connection to remote. Local backend will cache it.
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT 1 FROM ft1 LIMIT 1;
+FETCH c;
+ ?column?
+----------
+ 1
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..db18d88323 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,34 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Retry cached connections at the beginning of the remote xact
+-- in case remote backend is killed.
+-- Let's use a different application name for remote connection,
+-- so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- Generate a connection to remote. Local backend will cache it.
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check
+-- and kill it intentionally here. Note that, local backend still has
+-- the remote connection/backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Next query using the same foreign server should succeed if connection
+-- retry works.
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Subtransaction - remote backend is killed in the middle of a remote
+-- xact, and we don't do retry connection, hence the subsequent query
+-- using the same foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT 1 FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+COMMIT;
--
2.25.1
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-29 16:31 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-29 16:31 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/09/30 0:50, Bharath Rupireddy wrote:
> Thanks for the comments.
>
> On Tue, Sep 29, 2020 at 7:30 PM Fujii Masao <[email protected]> wrote:
>>
>> +1 to add debug3 message there. But this message doesn't seem to
>> match with what the error actually happened. What about something like
>> "could not start remote transaction on connection %p", instead?
>>
>
> Looks better. Changed.
>
>>
>> Also maybe it's better to append PQerrorMessage(entry->conn)?
>>
>
> Added. Now the log looks like [1].
>
>>
>> +-- Generate a connection to remote. Local backend will cache it.
>> +SELECT * FROM ft1 LIMIT 1;
>>
>> The result of this query would not be stable. Probably you need to,
>> for example, add ORDER BY or replace * with 1, etc.
>>
>
> Changed to SELECT 1 FROM ft1 LIMIT 1;
>
>>
>> +-- Retrieve pid of remote backend with application name fdw_retry_check
>> +-- and kill it intentionally here. Note that, local backend still has
>> +-- the remote connection/backend info in it's cache.
>> +SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
>> +backend_type = 'client backend' AND application_name = 'fdw_retry_check';
>>
>> Isn't this test fragile because there is no gurantee that the target backend
>> has exited just after calling pg_terminate_backend()?
>>
>
> I think this is okay, because pg_terminate_backend() sends SIGTERM to
> the backend, and upon receiving SIGTERM the signal handler die() will
> be called and since there is no query being executed on the backend by
> the time SIGTERM is received, it will exit immediately. Thoughts?
Yeah, basically you're right. But that backend *can* still be running
when the subsequent test query starts. I'm wondering if wait_pid()
(please see regress.c and sql/dblink.sql) should be used to ensure
the target backend disappeared.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-30 12:02 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-09-30 12:02 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Tue, Sep 29, 2020 at 10:01 PM Fujii Masao
<[email protected]> wrote:
>
> > I think this is okay, because pg_terminate_backend() sends SIGTERM to
> > the backend, and upon receiving SIGTERM the signal handler die() will
> > be called and since there is no query being executed on the backend by
> > the time SIGTERM is received, it will exit immediately. Thoughts?
>
> Yeah, basically you're right. But that backend *can* still be running
> when the subsequent test query starts. I'm wondering if wait_pid()
> (please see regress.c and sql/dblink.sql) should be used to ensure
> the target backend disappeared.
>
I think wait_pid() is not a generic function, and I'm unable to use
that inside postgres_fdw.sql. I think I need to recreate that function
for postgres_fdw.sql. For dblink, it's being created as part of
paths.source. Could you help me in doing so?
And another way, if we don't want to use wait_pid() is to have a
plpgsql stored procedure, that in a loop keeps on checking for the
backed pid from pg_stat_activity, exit when pid is 0. and then proceed
to issue the next foreign table query. Thoughts?
mypid = -1;
while (mypid != 0)
SELECT pid INTO mypid FROM pg_stat_activity WHERE backend_type =
'client backend' AND application_name = 'fdw_retry_check';
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-09-30 18:02 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-09-30 18:02 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/09/30 21:02, Bharath Rupireddy wrote:
> On Tue, Sep 29, 2020 at 10:01 PM Fujii Masao
> <[email protected]> wrote:
>>
>>> I think this is okay, because pg_terminate_backend() sends SIGTERM to
>>> the backend, and upon receiving SIGTERM the signal handler die() will
>>> be called and since there is no query being executed on the backend by
>>> the time SIGTERM is received, it will exit immediately. Thoughts?
>>
>> Yeah, basically you're right. But that backend *can* still be running
>> when the subsequent test query starts. I'm wondering if wait_pid()
>> (please see regress.c and sql/dblink.sql) should be used to ensure
>> the target backend disappeared.
>>
>
> I think wait_pid() is not a generic function, and I'm unable to use
> that inside postgres_fdw.sql. I think I need to recreate that function
> for postgres_fdw.sql. For dblink, it's being created as part of
> paths.source. Could you help me in doing so?
>
> And another way, if we don't want to use wait_pid() is to have a
> plpgsql stored procedure, that in a loop keeps on checking for the
> backed pid from pg_stat_activity, exit when pid is 0. and then proceed
> to issue the next foreign table query. Thoughts?
+1 for this approach! We can use plpgsql or DO command.
>
> mypid = -1;
> while (mypid != 0)
> SELECT pid INTO mypid FROM pg_stat_activity WHERE backend_type =
> 'client backend' AND application_name = 'fdw_retry_check';
Or we can just wait for the number of processes with
appname='fdw_retry_check' to be zero rather than checking the pid.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-01 12:14 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-10-01 12:14 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Wed, Sep 30, 2020 at 11:32 PM Fujii Masao
<[email protected]> wrote:
>
> > And another way, if we don't want to use wait_pid() is to have a
> > plpgsql stored procedure, that in a loop keeps on checking for the
> > backed pid from pg_stat_activity, exit when pid is 0. and then proceed
> > to issue the next foreign table query. Thoughts?
>
> +1 for this approach! We can use plpgsql or DO command.
>
Used plpgsql procedure as we have to use the procedure 2 times.
>
> >
> > mypid = -1;
> > while (mypid != 0)
> > SELECT pid INTO mypid FROM pg_stat_activity WHERE backend_type =
> > 'client backend' AND application_name = 'fdw_retry_check';
>
> Or we can just wait for the number of processes with
> appname='fdw_retry_check' to be zero rather than checking the pid.
>
Done.
Attaching v7 patch with above changes. Please review it.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/x-patch] v7-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (10.3K, ../../CALj2ACV1UWTMDPNUcGOH1on-RJ7ARPx4G0pDyxQAhVSxdfZamw@mail.gmail.com/2-v7-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
From e2a85116116e79c76a7b0fcfc1a25eff57627ed4 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Thu, 1 Oct 2020 15:16:26 +0530
Subject: [PATCH v7] Retry Cached Remote Connections For postgres_fdw
Remote connections are cached for postgres_fdw in the local
backend. There are high chances that the remote backend may
not be available i.e. it can get killed, the subsequent foreign
queries from local backend/session that use cached connection
will fail as the remote backend would have become unavailable.
This patch proposes a retry mechanism. Local backend/session
uses cached connection and if it receives connection bad error,
it deletes the cached entry and retry to get a new connection.
This retry happens only at the start of remote xact.
---
contrib/postgres_fdw/connection.c | 55 +++++++++---
.../postgres_fdw/expected/postgres_fdw.out | 85 +++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 64 ++++++++++++++
3 files changed, 192 insertions(+), 12 deletions(-)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..441124963f 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also, if previous attempt to
+ * start new remote transaction failed on the cached connection, disconnect
+ * it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,37 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote xact
+ * is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ ereport(DEBUG3,
+ (errmsg("could not start remote transaction on connection %p",
+ entry->conn)),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..09d0578d05 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,88 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Connection retry feature
+-- Retry cached connections at the beginning of the remote xact in case remote
+-- backend is killed. Let's use a different application name for remote
+-- connection, so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- This procedure waits until the terminated backend has really gone away. We
+-- also had to check for wait event type and wait event of the terminated
+-- backend's row from pg_stat_activity. Otherwise, the usage of this procedure
+-- in an explicit txn block(BEGIN - END) after terminating the backend would
+-- still have an entry with wait event type wait event null, as we have not yet
+-- committed the txn. The entry of the terminated backend from pg_stat_activity
+-- would be removed only after the txn commit.
+CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
+LANGUAGE plpgsql
+AS $$
+DECLARE proccnt int;
+BEGIN
+ LOOP
+ SELECT count(*) INTO proccnt FROM pg_stat_activity
+ WHERE backend_type = 'client backend' AND
+ application_name = 'fdw_retry_check' AND
+ wait_event_type IS NOT NULL AND
+ wait_event IS NOT NULL;
+ EXIT WHEN proccnt = 0;
+ END LOOP;
+END;
+$$;
+-- Connection retry feature test case 001:
+-- Generate a connection to remote. Local backend will cache it.
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check and
+-- kill intentionally here. Note that, local backend still has the remote
+-- backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Despite issuing terminate, there are chances that the backend is still not
+-- actually terminated. Hence, wait for the terminated backend to go away.
+CALL wait_for_backend_termination();
+-- Next query using the same foreign server should succeed if connection retry
+-- works.
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Connection retry feature test case 002:
+-- Subtransaction - remote backend is killed in the middle of a remote xact and
+-- we don't do retry connection, hence the subsequent query using the same
+-- foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT 1 FROM ft1 LIMIT 1;
+FETCH c;
+ ?column?
+----------
+ 1
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+CALL wait_for_backend_termination();
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
+-- Clean up
+DROP PROCEDURE wait_for_backend_termination();
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..17246f4176 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,67 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Connection retry feature
+-- Retry cached connections at the beginning of the remote xact in case remote
+-- backend is killed. Let's use a different application name for remote
+-- connection, so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- This procedure waits until the terminated backend has really gone away. We
+-- also had to check for wait event type and wait event of the terminated
+-- backend's row from pg_stat_activity. Otherwise, the usage of this procedure
+-- in an explicit txn block(BEGIN - END) after terminating the backend would
+-- still have an entry with wait event type wait event null, as we have not yet
+-- committed the txn. The entry of the terminated backend from pg_stat_activity
+-- would be removed only after the txn commit.
+CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
+LANGUAGE plpgsql
+AS $$
+DECLARE proccnt int;
+BEGIN
+ LOOP
+ SELECT count(*) INTO proccnt FROM pg_stat_activity
+ WHERE backend_type = 'client backend' AND
+ application_name = 'fdw_retry_check' AND
+ wait_event_type IS NOT NULL AND
+ wait_event IS NOT NULL;
+ EXIT WHEN proccnt = 0;
+ END LOOP;
+END;
+$$;
+
+-- Connection retry feature test case 001:
+-- Generate a connection to remote. Local backend will cache it.
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check and
+-- kill intentionally here. Note that, local backend still has the remote
+-- backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Despite issuing terminate, there are chances that the backend is still not
+-- actually terminated. Hence, wait for the terminated backend to go away.
+CALL wait_for_backend_termination();
+
+-- Next query using the same foreign server should succeed if connection retry
+-- works.
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Connection retry feature test case 002:
+-- Subtransaction - remote backend is killed in the middle of a remote xact and
+-- we don't do retry connection, hence the subsequent query using the same
+-- foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT 1 FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+CALL wait_for_backend_termination();
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+COMMIT;
+
+-- Clean up
+DROP PROCEDURE wait_for_backend_termination();
\ No newline at end of file
--
2.25.1
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-01 14:39 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-10-01 14:39 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/10/01 21:14, Bharath Rupireddy wrote:
> On Wed, Sep 30, 2020 at 11:32 PM Fujii Masao
> <[email protected]> wrote:
>>
>>> And another way, if we don't want to use wait_pid() is to have a
>>> plpgsql stored procedure, that in a loop keeps on checking for the
>>> backed pid from pg_stat_activity, exit when pid is 0. and then proceed
>>> to issue the next foreign table query. Thoughts?
>>
>> +1 for this approach! We can use plpgsql or DO command.
>>
>
> Used plpgsql procedure as we have to use the procedure 2 times.
>
>>
>>>
>>> mypid = -1;
>>> while (mypid != 0)
>>> SELECT pid INTO mypid FROM pg_stat_activity WHERE backend_type =
>>> 'client backend' AND application_name = 'fdw_retry_check';
>>
>> Or we can just wait for the number of processes with
>> appname='fdw_retry_check' to be zero rather than checking the pid.
>>
>
> Done.
>
> Attaching v7 patch with above changes. Please review it.
Thanks for updating the patch!
+-- committed the txn. The entry of the terminated backend from pg_stat_activity
+-- would be removed only after the txn commit.
pg_stat_clear_snapshot() can be used to reset the entry.
+ EXIT WHEN proccnt = 0;
+ END LOOP;
Isn't it better to sleep here, to avoid th busy loop?
So what I thought was something like
CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
LANGUAGE plpgsql
AS $$
BEGIN
LOOP
PERFORM * FROM pg_stat_activity WHERE application_name = 'fdw_retry_check';
EXIT WHEN NOT FOUND;
PERFORM pg_sleep(1), pg_stat_clear_snapshot();
END LOOP;
END;
$$;
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-01 15:46 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-10-01 15:46 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Thu, Oct 1, 2020 at 8:10 PM Fujii Masao <[email protected]> wrote:
>
> pg_stat_clear_snapshot() can be used to reset the entry.
>
Thanks. I wasn't knowing it.
>
> + EXIT WHEN proccnt = 0;
> + END LOOP;
>
> Isn't it better to sleep here, to avoid th busy loop?
>
+1.
>
> So what I thought was something like
>
> CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
> LANGUAGE plpgsql
> AS $$
> BEGIN
> LOOP
> PERFORM * FROM pg_stat_activity WHERE application_name = 'fdw_retry_check';
> EXIT WHEN NOT FOUND;
> PERFORM pg_sleep(1), pg_stat_clear_snapshot();
> END LOOP;
> END;
> $$;
>
Changed.
Attaching v8 patch, please review it.. Both make check and make
check-world passes on v8.
I have another question not related to this patch: though we have
wait_pid() function, we are not able to use it like
pg_terminate_backend() in other modules, wouldn't be nice if we can
make it generic under the name pg_wait_pid() and usable across all pg
modules?
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/octet-stream] v8-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (9.3K, ../../CALj2ACU4yGdJ_a5ikuq_VdX4uJBph2S_bWE1bNhXNPEn-MCV0w@mail.gmail.com/2-v8-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
From 7aa1b7e1b9820a92beded06a965275fd237040cd Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Thu, 1 Oct 2020 21:13:05 +0530
Subject: [PATCH v8] Retry Cached Remote Connections For postgres_fdw
Remote connections are cached for postgres_fdw in the local
backend. There are high chances that the remote backend may
not be available i.e. it can get killed, the subsequent foreign
queries from local backend/session that use cached connection
will fail as the remote backend would have become unavailable.
This patch proposes a retry mechanism. Local backend/session
uses cached connection and if it receives connection bad error,
it deletes the cached entry and retry to get a new connection.
This retry happens only at the start of remote xact.
---
contrib/postgres_fdw/connection.c | 55 +++++++++++---
.../postgres_fdw/expected/postgres_fdw.out | 76 +++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 55 ++++++++++++++
3 files changed, 174 insertions(+), 12 deletions(-)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..441124963f 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also, if previous attempt to
+ * start new remote transaction failed on the cached connection, disconnect
+ * it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,37 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here, while the remote xact
+ * is going to begin. Broken connection will be detected and the
+ * connection is retried. We do this only once during each begin remote
+ * xact call, if the connection is still broken after the retry attempt,
+ * then the query will fail.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ ereport(DEBUG3,
+ (errmsg("could not start remote transaction on connection %p",
+ entry->conn)),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..db039237e1 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,79 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- Connection retry feature
+-- Retry cached connections at the beginning of the remote xact in case remote
+-- backend is killed. Let's use a different application name for remote
+-- connection, so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+-- This procedure waits until the terminated backend has really gone away. We
+-- do pg_stat_clear_snapshot() to fetch the new snapshot of the stats.
+CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = 'fdw_retry_check';
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$;
+-- Connection retry feature test case 001:
+-- Generate a connection to remote. Local backend will cache it.
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Retrieve pid of remote backend with application name fdw_retry_check and
+-- kill intentionally here. Note that, local backend still has the remote
+-- backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+-- Despite issuing terminate, there are chances that the backend is still not
+-- actually terminated. Hence, wait for the terminated backend to go away.
+CALL wait_for_backend_termination();
+-- Next query using the same foreign server should succeed if connection retry
+-- works.
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Connection retry feature test case 002:
+-- Subtransaction - remote backend is killed in the middle of a remote xact and
+-- we don't do retry connection, hence the subsequent query using the same
+-- foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT 1 FROM ft1 LIMIT 1;
+FETCH c;
+ ?column?
+----------
+ 1
+(1 row)
+
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
+CALL wait_for_backend_termination();
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
+-- Clean up
+DROP PROCEDURE wait_for_backend_termination();
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..3d4eb8414d 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,58 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- Connection retry feature
+-- Retry cached connections at the beginning of the remote xact in case remote
+-- backend is killed. Let's use a different application name for remote
+-- connection, so that this test will not kill other backends wrongly.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+
+-- This procedure waits until the terminated backend has really gone away. We
+-- do pg_stat_clear_snapshot() to fetch the new snapshot of the stats.
+CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = 'fdw_retry_check';
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$;
+
+-- Connection retry feature test case 001:
+-- Generate a connection to remote. Local backend will cache it.
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Retrieve pid of remote backend with application name fdw_retry_check and
+-- kill intentionally here. Note that, local backend still has the remote
+-- backend info in it's cache.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+
+-- Despite issuing terminate, there are chances that the backend is still not
+-- actually terminated. Hence, wait for the terminated backend to go away.
+CALL wait_for_backend_termination();
+
+-- Next query using the same foreign server should succeed if connection retry
+-- works.
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Connection retry feature test case 002:
+-- Subtransaction - remote backend is killed in the middle of a remote xact and
+-- we don't do retry connection, hence the subsequent query using the same
+-- foreign server should fail.
+BEGIN;
+DECLARE c CURSOR FOR SELECT 1 FROM ft1 LIMIT 1;
+FETCH c;
+SAVEPOINT s;
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+CALL wait_for_backend_termination();
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+COMMIT;
+
+-- Clean up
+DROP PROCEDURE wait_for_backend_termination();
--
2.25.1
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-02 18:00 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-10-02 18:00 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/10/02 0:46, Bharath Rupireddy wrote:
> On Thu, Oct 1, 2020 at 8:10 PM Fujii Masao <[email protected]> wrote:
>>
>> pg_stat_clear_snapshot() can be used to reset the entry.
>>
>
> Thanks. I wasn't knowing it.
>
>>
>> + EXIT WHEN proccnt = 0;
>> + END LOOP;
>>
>> Isn't it better to sleep here, to avoid th busy loop?
>>
>
> +1.
>
>>
>> So what I thought was something like
>>
>> CREATE OR REPLACE PROCEDURE wait_for_backend_termination()
>> LANGUAGE plpgsql
>> AS $$
>> BEGIN
>> LOOP
>> PERFORM * FROM pg_stat_activity WHERE application_name = 'fdw_retry_check';
>> EXIT WHEN NOT FOUND;
>> PERFORM pg_sleep(1), pg_stat_clear_snapshot();
>> END LOOP;
>> END;
>> $$;
>>
>
> Changed.
>
> Attaching v8 patch, please review it.. Both make check and make
> check-world passes on v8.
Thanks for updating the patch! It basically looks good to me.
I tweaked the patch as follows.
+ if (!entry->conn ||
+ PQstatus(entry->conn) != CONNECTION_BAD ||
With the above change, if entry->conn is NULL, an error is thrown and no new
connection is reestablished. But why? IMO it's more natural to reestablish
new connection in that case. So I removed "!entry->conn" from the above
condition.
+ ereport(DEBUG3,
+ (errmsg("could not start remote transaction on connection %p",
+ entry->conn)),
I replaced errmsg() with errmsg_internal() because the translation of
this debug message is not necessary.
+SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
+backend_type = 'client backend' AND application_name = 'fdw_retry_check';
+CALL wait_for_backend_termination();
Since we always use pg_terminate_backend() and wait_for_backend_termination()
together, I merged them into one function.
I simplied the comments on the regression test.
Attached is the updated version of the patch. If this patch is ok,
I'd like to mark it as ready for committer.
> I have another question not related to this patch: though we have
> wait_pid() function, we are not able to use it like
> pg_terminate_backend() in other modules, wouldn't be nice if we can
> make it generic under the name pg_wait_pid() and usable across all pg
> modules?
I thought that, too. But I could not come up with good idea for *real* use case
of that function. At least that's useful for the regression test, though.
Anyway, IMO it's worth proposing that and hearing more opinions about that
from other hackers.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..901d3a4661 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also, if previous attempt to
+ * start new remote transaction failed on the cached connection, disconnect
+ * it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,35 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here when starting
+ * a new remote transaction. If broken connection is detected,
+ * we try to reestablish a new connection. If broken connection is
+ * detected again here, we give up getting a connection.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ ereport(DEBUG3,
+ (errmsg_internal("could not start remote transaction on connection %p",
+ entry->conn)),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..2c5614073f 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,51 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- ===================================================================
+-- reestablish new connection
+-- ===================================================================
+-- Terminate the backend having the specified application_name and wait for
+-- the termination to complete.
+CREATE OR REPLACE PROCEDURE terminate_backend_and_wait(appname text) AS $$
+BEGIN
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity
+ WHERE application_name = appname;
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = appname;
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+-- Change application_name of remote connection to special one
+-- so that we can easily terminate the connection later.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Terminate the remote connection.
+CALL terminate_backend_and_wait('fdw_retry_check');
+-- This query should detect the broken connection when starting new remote
+-- transaction, reestablish new connection, and then succeed.
+BEGIN;
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- If the query detects the broken connection when starting new remote
+-- subtransaction, it doesn't reestablish new connection and should fail.
+CALL terminate_backend_and_wait('fdw_retry_check');
+SAVEPOINT s;
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
+-- Clean up
+DROP PROCEDURE terminate_backend_and_wait(text);
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..4da1f78956 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,44 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- ===================================================================
+-- reestablish new connection
+-- ===================================================================
+
+-- Terminate the backend having the specified application_name and wait for
+-- the termination to complete.
+CREATE OR REPLACE PROCEDURE terminate_backend_and_wait(appname text) AS $$
+BEGIN
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity
+ WHERE application_name = appname;
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = appname;
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+
+-- Change application_name of remote connection to special one
+-- so that we can easily terminate the connection later.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Terminate the remote connection.
+CALL terminate_backend_and_wait('fdw_retry_check');
+
+-- This query should detect the broken connection when starting new remote
+-- transaction, reestablish new connection, and then succeed.
+BEGIN;
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- If the query detects the broken connection when starting new remote
+-- subtransaction, it doesn't reestablish new connection and should fail.
+CALL terminate_backend_and_wait('fdw_retry_check');
+SAVEPOINT s;
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+COMMIT;
+
+-- Clean up
+DROP PROCEDURE terminate_backend_and_wait(text);
Attachments:
[text/plain] v9-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (6.8K, ../../[email protected]/2-v9-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..901d3a4661 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also, if previous attempt to
+ * start new remote transaction failed on the cached connection, disconnect
+ * it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,35 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here when starting
+ * a new remote transaction. If broken connection is detected,
+ * we try to reestablish a new connection. If broken connection is
+ * detected again here, we give up getting a connection.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ ereport(DEBUG3,
+ (errmsg_internal("could not start remote transaction on connection %p",
+ entry->conn)),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..2c5614073f 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,51 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- ===================================================================
+-- reestablish new connection
+-- ===================================================================
+-- Terminate the backend having the specified application_name and wait for
+-- the termination to complete.
+CREATE OR REPLACE PROCEDURE terminate_backend_and_wait(appname text) AS $$
+BEGIN
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity
+ WHERE application_name = appname;
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = appname;
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+-- Change application_name of remote connection to special one
+-- so that we can easily terminate the connection later.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Terminate the remote connection.
+CALL terminate_backend_and_wait('fdw_retry_check');
+-- This query should detect the broken connection when starting new remote
+-- transaction, reestablish new connection, and then succeed.
+BEGIN;
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- If the query detects the broken connection when starting new remote
+-- subtransaction, it doesn't reestablish new connection and should fail.
+CALL terminate_backend_and_wait('fdw_retry_check');
+SAVEPOINT s;
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
+-- Clean up
+DROP PROCEDURE terminate_backend_and_wait(text);
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..4da1f78956 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,44 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- ===================================================================
+-- reestablish new connection
+-- ===================================================================
+
+-- Terminate the backend having the specified application_name and wait for
+-- the termination to complete.
+CREATE OR REPLACE PROCEDURE terminate_backend_and_wait(appname text) AS $$
+BEGIN
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity
+ WHERE application_name = appname;
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = appname;
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+
+-- Change application_name of remote connection to special one
+-- so that we can easily terminate the connection later.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Terminate the remote connection.
+CALL terminate_backend_and_wait('fdw_retry_check');
+
+-- This query should detect the broken connection when starting new remote
+-- transaction, reestablish new connection, and then succeed.
+BEGIN;
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- If the query detects the broken connection when starting new remote
+-- subtransaction, it doesn't reestablish new connection and should fail.
+CALL terminate_backend_and_wait('fdw_retry_check');
+SAVEPOINT s;
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+COMMIT;
+
+-- Clean up
+DROP PROCEDURE terminate_backend_and_wait(text);
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-03 11:40 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-10-03 11:40 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Fri, Oct 2, 2020 at 11:30 PM Fujii Masao <[email protected]> wrote:
>
> > Attaching v8 patch, please review it.. Both make check and make
> > check-world passes on v8.
>
> Thanks for updating the patch! It basically looks good to me.
> I tweaked the patch as follows.
>
> + if (!entry->conn ||
> + PQstatus(entry->conn) != CONNECTION_BAD ||
>
> With the above change, if entry->conn is NULL, an error is thrown and no new
> connection is reestablished. But why? IMO it's more natural to reestablish
> new connection in that case. So I removed "!entry->conn" from the above
> condition.
>
Yeah, that makes sense.
>
> + ereport(DEBUG3,
> + (errmsg("could not start remote transaction on connection %p",
> + entry->conn)),
>
> I replaced errmsg() with errmsg_internal() because the translation of
> this debug message is not necessary.
>
I'm okay with this as we don't have any specific strings that need
translation in the debug message. But, should we also try to have
errmsg_internal in a few other places in connection.c?
errmsg("could not obtain message string for remote error"),
errmsg("cannot PREPARE a transaction that has
operated on postgres_fdw foreign tables")));
errmsg("password is required"),
I see the errmsg() with plain texts in other places in the code base
as well. Is it that we look at the error message and if it is a plain
text(without database objects or table data), we decide to have no
translation? Or is there any other policy?
>
> +SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
> +backend_type = 'client backend' AND application_name = 'fdw_retry_check';
> +CALL wait_for_backend_termination();
>
> Since we always use pg_terminate_backend() and wait_for_backend_termination()
> together, I merged them into one function.
>
> I simplied the comments on the regression test.
>
+1. I slightly adjusted comments in connection.c and ran pg_indent to
keep them upt 80 char limit.
>
> Attached is the updated version of the patch. If this patch is ok,
> I'd like to mark it as ready for committer.
>
Thanks. Attaching v10 patch. Please have a look.
>
> > I have another question not related to this patch: though we have
> > wait_pid() function, we are not able to use it like
> > pg_terminate_backend() in other modules, wouldn't be nice if we can
> > make it generic under the name pg_wait_pid() and usable across all pg
> > modules?
>
> I thought that, too. But I could not come up with good idea for *real* use case
> of that function. At least that's useful for the regression test, though.
> Anyway, IMO it's worth proposing that and hearing more opinions about that
> from other hackers.
>
Yes it will be useful for testing when coupled with
pg_terminate_backend(). I will post the idea in a separate thread soon
for more thoughts.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/x-patch] v10-Retry-Cached-Remote-Connections-For-postgres_fdw.patch (7.8K, ../../CALj2ACUFyeEtjqXrShMbiRuNmKfMxRs8Fg2YMJ0Y9AJGgJ5ahw@mail.gmail.com/2-v10-Retry-Cached-Remote-Connections-For-postgres_fdw.patch)
download | inline diff:
From 68d764690fc0409ee15afbbbd00974e0d43116cf Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Sat, 3 Oct 2020 05:49:18 +0530
Subject: [PATCH v10] Retry Cached Remote Connections For postgres_fdw
Remote connections are cached for postgres_fdw in the local
backend. There are high chances that the remote backend may
not be available i.e. it can get killed, the subsequent foreign
queries from local backend/session that use cached connection
will fail as the remote backend would have become unavailable.
This patch proposes a retry mechanism. Local backend/session
uses cached connection and if it receives connection bad error,
it deletes the cached entry and retry to get a new connection.
This retry happens only at the start of remote xact.
---
contrib/postgres_fdw/connection.c | 53 ++++++++++++++-----
.../postgres_fdw/expected/postgres_fdw.out | 48 +++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 41 ++++++++++++++
3 files changed, 130 insertions(+), 12 deletions(-)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 08daf26fdf..5fa4b634c3 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -108,6 +108,7 @@ PGconn *
GetConnection(UserMapping *user, bool will_prep_stmt)
{
bool found;
+ volatile bool retry_conn = false;
ConnCacheEntry *entry;
ConnCacheKey key;
@@ -159,23 +160,25 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
/* Reject further use of connections which failed abort cleanup. */
pgfdw_reject_incomplete_xact_state_change(entry);
+retry:
/*
* If the connection needs to be remade due to invalidation, disconnect as
- * soon as we're out of all transactions.
+ * soon as we're out of all transactions. Also, if previous attempt to
+ * start new remote transaction failed on the cached connection,
+ * disconnect it to retry a new connection.
*/
- if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
+ if ((entry->conn != NULL && entry->invalidated &&
+ entry->xact_depth == 0) || retry_conn)
{
- elog(DEBUG3, "closing connection %p for option changes to take effect",
- entry->conn);
+ if (retry_conn)
+ elog(DEBUG3, "closing connection %p to reestablish a new one",
+ entry->conn);
+ else
+ elog(DEBUG3, "closing connection %p for option changes to take effect",
+ entry->conn);
disconnect_pg_server(entry);
}
- /*
- * We don't check the health of cached connection here, because it would
- * require some overhead. Broken connection will be detected when the
- * connection is actually used.
- */
-
/*
* If cache entry doesn't have a connection, we have to establish a new
* connection. (If connect_pg_server throws an error, the cache entry
@@ -206,9 +209,35 @@ GetConnection(UserMapping *user, bool will_prep_stmt)
}
/*
- * Start a new transaction or subtransaction if needed.
+ * We check the health of the cached connection here when starting a new
+ * remote transaction. If a broken connection is detected in the first
+ * attempt, we try to reestablish a new connection. If broken connection
+ * is detected again here, we give up getting a connection.
*/
- begin_remote_xact(entry);
+ PG_TRY();
+ {
+ /* Start a new transaction or subtransaction if needed. */
+ begin_remote_xact(entry);
+ retry_conn = false;
+ }
+ PG_CATCH();
+ {
+ if (PQstatus(entry->conn) != CONNECTION_BAD ||
+ entry->xact_depth > 0 ||
+ retry_conn)
+ PG_RE_THROW();
+ retry_conn = true;
+ }
+ PG_END_TRY();
+
+ if (retry_conn)
+ {
+ ereport(DEBUG3,
+ (errmsg_internal("could not start remote transaction on connection %p",
+ entry->conn)),
+ errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
+ goto retry;
+ }
/* Remember if caller will prepare statements */
entry->have_prep_stmt |= will_prep_stmt;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 10e23d02ed..2c5614073f 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -8987,3 +8987,51 @@ PREPARE TRANSACTION 'fdw_tpc';
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
ROLLBACK;
WARNING: there is no transaction in progress
+-- ===================================================================
+-- reestablish new connection
+-- ===================================================================
+-- Terminate the backend having the specified application_name and wait for
+-- the termination to complete.
+CREATE OR REPLACE PROCEDURE terminate_backend_and_wait(appname text) AS $$
+BEGIN
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity
+ WHERE application_name = appname;
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = appname;
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+-- Change application_name of remote connection to special one
+-- so that we can easily terminate the connection later.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- Terminate the remote connection.
+CALL terminate_backend_and_wait('fdw_retry_check');
+-- This query should detect the broken connection when starting new remote
+-- transaction, reestablish new connection, and then succeed.
+BEGIN;
+SELECT 1 FROM ft1 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+-- If the query detects the broken connection when starting new remote
+-- subtransaction, it doesn't reestablish new connection and should fail.
+CALL terminate_backend_and_wait('fdw_retry_check');
+SAVEPOINT s;
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+ERROR: server closed the connection unexpectedly
+ This probably means the server terminated abnormally
+ before or while processing the request.
+CONTEXT: remote SQL command: SAVEPOINT s2
+COMMIT;
+-- Clean up
+DROP PROCEDURE terminate_backend_and_wait(text);
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 78156d10b4..4da1f78956 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -2653,3 +2653,44 @@ SELECT count(*) FROM ft1;
-- error here
PREPARE TRANSACTION 'fdw_tpc';
ROLLBACK;
+
+-- ===================================================================
+-- reestablish new connection
+-- ===================================================================
+
+-- Terminate the backend having the specified application_name and wait for
+-- the termination to complete.
+CREATE OR REPLACE PROCEDURE terminate_backend_and_wait(appname text) AS $$
+BEGIN
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity
+ WHERE application_name = appname;
+ LOOP
+ PERFORM * FROM pg_stat_activity WHERE application_name = appname;
+ EXIT WHEN NOT FOUND;
+ PERFORM pg_sleep(1), pg_stat_clear_snapshot();
+ END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+
+-- Change application_name of remote connection to special one
+-- so that we can easily terminate the connection later.
+ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check');
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- Terminate the remote connection.
+CALL terminate_backend_and_wait('fdw_retry_check');
+
+-- This query should detect the broken connection when starting new remote
+-- transaction, reestablish new connection, and then succeed.
+BEGIN;
+SELECT 1 FROM ft1 LIMIT 1;
+
+-- If the query detects the broken connection when starting new remote
+-- subtransaction, it doesn't reestablish new connection and should fail.
+CALL terminate_backend_and_wait('fdw_retry_check');
+SAVEPOINT s;
+SELECT 1 FROM ft1 LIMIT 1; -- should fail
+COMMIT;
+
+-- Clean up
+DROP PROCEDURE terminate_backend_and_wait(text);
--
2.25.1
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-05 04:15 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Fujii Masao @ 2020-10-05 04:15 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/10/03 20:40, Bharath Rupireddy wrote:
> On Fri, Oct 2, 2020 at 11:30 PM Fujii Masao <[email protected]> wrote:
>>
>>> Attaching v8 patch, please review it.. Both make check and make
>>> check-world passes on v8.
>>
>> Thanks for updating the patch! It basically looks good to me.
>> I tweaked the patch as follows.
>>
>> + if (!entry->conn ||
>> + PQstatus(entry->conn) != CONNECTION_BAD ||
>>
>> With the above change, if entry->conn is NULL, an error is thrown and no new
>> connection is reestablished. But why? IMO it's more natural to reestablish
>> new connection in that case. So I removed "!entry->conn" from the above
>> condition.
>>
>
> Yeah, that makes sense.
>
>>
>> + ereport(DEBUG3,
>> + (errmsg("could not start remote transaction on connection %p",
>> + entry->conn)),
>>
>> I replaced errmsg() with errmsg_internal() because the translation of
>> this debug message is not necessary.
>>
>
> I'm okay with this as we don't have any specific strings that need
> translation in the debug message. But, should we also try to have
> errmsg_internal in a few other places in connection.c?
>
> errmsg("could not obtain message string for remote error"),
> errmsg("cannot PREPARE a transaction that has
> operated on postgres_fdw foreign tables")));
> errmsg("password is required"),
>
> I see the errmsg() with plain texts in other places in the code base
> as well. Is it that we look at the error message and if it is a plain
> text(without database objects or table data), we decide to have no
> translation? Or is there any other policy?
I was thinking that elog() basically should be used to report this
debug message, instead, but you used ereport() because maybe
you'd like to add detail message about connection error. Is this
understanding right? elog() uses errmsg_internal(). So if ereport()
is used as an aternative of elog() for some reasons,
IMO errmsg_internal() should be used. Thought?
OTOH, the messages you mentioned are not debug ones,
so basically ereport() and errmsg() should be used, I think.
>
>>
>> +SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE
>> +backend_type = 'client backend' AND application_name = 'fdw_retry_check';
>> +CALL wait_for_backend_termination();
>>
>> Since we always use pg_terminate_backend() and wait_for_backend_termination()
>> together, I merged them into one function.
>>
>> I simplied the comments on the regression test.
>>
>
> +1. I slightly adjusted comments in connection.c and ran pg_indent to
> keep them upt 80 char limit.
>
>>
>> Attached is the updated version of the patch. If this patch is ok,
>> I'd like to mark it as ready for committer.
>>
>
> Thanks. Attaching v10 patch. Please have a look.
Thanks for updating the patch! I will mark the patch as ready for committer in CF.
Barring any objections, I will commit that.
>
>>
>>> I have another question not related to this patch: though we have
>>> wait_pid() function, we are not able to use it like
>>> pg_terminate_backend() in other modules, wouldn't be nice if we can
>>> make it generic under the name pg_wait_pid() and usable across all pg
>>> modules?
>>
>> I thought that, too. But I could not come up with good idea for *real* use case
>> of that function. At least that's useful for the regression test, though.
>> Anyway, IMO it's worth proposing that and hearing more opinions about that
>> from other hackers.
>>
>
> Yes it will be useful for testing when coupled with
> pg_terminate_backend(). I will post the idea in a separate thread soon
> for more thoughts.
Sounds good!
ISTM that he function should at least check the target process is PostgreSQL one.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-05 11:32 Bharath Rupireddy <[email protected]>
parent: Fujii Masao <[email protected]>
0 siblings, 1 reply; 989+ messages in thread
From: Bharath Rupireddy @ 2020-10-05 11:32 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: pgsql-hackers
On Mon, Oct 5, 2020 at 9:45 AM Fujii Masao <[email protected]> wrote:
>
> > I see the errmsg() with plain texts in other places in the code base
> > as well. Is it that we look at the error message and if it is a plain
> > text(without database objects or table data), we decide to have no
> > translation? Or is there any other policy?
>
> I was thinking that elog() basically should be used to report this
> debug message, instead, but you used ereport() because maybe
> you'd like to add detail message about connection error. Is this
> understanding right? elog() uses errmsg_internal().
>
Yes that's correct.
>
> So if ereport() is used as an aternative of elog() for some reasons,
> IMO errmsg_internal() should be used. Thought?
>
Yes, this is apt for our case.
>
> OTOH, the messages you mentioned are not debug ones,
> so basically ereport() and errmsg() should be used, I think.
>
In connection.c file, yes they are of ERROR type. Looks like it's not
a standard to use errmsg_internal for DEBUG messages that require no
translation with ereport
(errmsg("wrote block details for %d blocks", num_blocks)));
(errmsg("MultiXact member stop limit is now %u based on MultiXact %u
(errmsg("oldest MultiXactId member is at offset %u",
However, there are few other places, where errmsg_internal is used for
DEBUG purposes.
(errmsg_internal("finished verifying presence of "
(errmsg_internal("%s(%d) name: %s; blockState:
Having said that, IMHO it's better to keep the way it is currently in
the code base.
>
> > Thanks. Attaching v10 patch. Please have a look.
>
> Thanks for updating the patch! I will mark the patch as ready for committer in CF.
> Barring any objections, I will commit that.
>
Thanks a lot for the review comments.
> >>
> >>> I have another question not related to this patch: though we have
> >>> wait_pid() function, we are not able to use it like
> >>> pg_terminate_backend() in other modules, wouldn't be nice if we can
> >>> make it generic under the name pg_wait_pid() and usable across all pg
> >>> modules?
> >>
> >> I thought that, too. But I could not come up with good idea for *real* use case
> >> of that function. At least that's useful for the regression test, though.
> >> Anyway, IMO it's worth proposing that and hearing more opinions about that
> >> from other hackers.
> >>
> >
> > Yes it will be useful for testing when coupled with
> > pg_terminate_backend(). I will post the idea in a separate thread soon
> > for more thoughts.
>
> Sounds good!
> ISTM that he function should at least check the target process is PostgreSQL one.
>
Thanks. I will take care of this point.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 989+ messages in thread
* Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away
@ 2020-10-06 01:54 Fujii Masao <[email protected]>
parent: Bharath Rupireddy <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Fujii Masao @ 2020-10-06 01:54 UTC (permalink / raw)
To: Bharath Rupireddy <[email protected]>; +Cc: pgsql-hackers
On 2020/10/05 20:32, Bharath Rupireddy wrote:
> On Mon, Oct 5, 2020 at 9:45 AM Fujii Masao <[email protected]> wrote:
>>
>>> I see the errmsg() with plain texts in other places in the code base
>>> as well. Is it that we look at the error message and if it is a plain
>>> text(without database objects or table data), we decide to have no
>>> translation? Or is there any other policy?
>>
>> I was thinking that elog() basically should be used to report this
>> debug message, instead, but you used ereport() because maybe
>> you'd like to add detail message about connection error. Is this
>> understanding right? elog() uses errmsg_internal().
>>
>
> Yes that's correct.
>
>>
>> So if ereport() is used as an aternative of elog() for some reasons,
>> IMO errmsg_internal() should be used. Thought?
>>
>
> Yes, this is apt for our case.
>
>>
>> OTOH, the messages you mentioned are not debug ones,
>> so basically ereport() and errmsg() should be used, I think.
>>
>
> In connection.c file, yes they are of ERROR type. Looks like it's not
> a standard to use errmsg_internal for DEBUG messages that require no
> translation with ereport
>
> (errmsg("wrote block details for %d blocks", num_blocks)));
> (errmsg("MultiXact member stop limit is now %u based on MultiXact %u
> (errmsg("oldest MultiXactId member is at offset %u",
>
> However, there are few other places, where errmsg_internal is used for
> DEBUG purposes.
>
> (errmsg_internal("finished verifying presence of "
> (errmsg_internal("%s(%d) name: %s; blockState:
>
> Having said that, IMHO it's better to keep the way it is currently in
> the code base.
Agreed.
>
>>
>>> Thanks. Attaching v10 patch. Please have a look.
>>
>> Thanks for updating the patch! I will mark the patch as ready for committer in CF.
>> Barring any objections, I will commit that.
>>
>
> Thanks a lot for the review comments.
I pushed the patch. Thanks!
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v5 2/3] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Author: Álvaro Herrera <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/[email protected]
---
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 | 31 +++++++++++++++---------
6 files changed, 52 insertions(+), 30 deletions(-)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index d34136d2e94..6bff0032db2 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options pg_attribute_unused(), Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..1be8ea4845a 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options,
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..9b5d7424dda 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -282,13 +282,18 @@ typedef struct TM_IndexDeleteOp
#define TABLE_INSERT_FROZEN 0x0004
#define TABLE_INSERT_NO_LOGICAL 0x0008
+/* "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 */
+
/* flag bits for table_tuple_lock */
/* Follow tuples whose update is in progress if lock modes don't conflict */
#define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS (1 << 0)
/* Follow update chain and lock latest version of tuple */
#define TUPLE_LOCK_FLAG_FIND_LAST_VERSION (1 << 1)
-
/* Typedef for callback function for table_index_build_scan */
typedef void (*IndexBuildCallback) (Relation index,
ItemPointer tid,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1516,10 +1522,11 @@ table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots,
* tid - TID of tuple to be deleted
* cid - delete command ID (used for visibility test, and stored into
* cmax if successful)
+ * options - bitmask of options. Supported values:
+ * TABLE_DELETE_CHANGING_PARTITION: the tuple is being moved to another
+ * partition table due to an update of the partition key.
* crosscheck - if not InvalidSnapshot, also check tuple against this
* wait - true if should wait for any conflicting update to commit/abort
- * changingPart - true iff the tuple is being moved to another partition
- * table due to an update of the partition key. Otherwise, false.
*
* Output parameters:
* tmfd - filled in failure cases (see below)
@@ -1534,12 +1541,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)
+ uint32 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);
}
/*
@@ -1553,6 +1560,7 @@ table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
* otid - TID of old tuple to be replaced
* cid - update command ID (used for visibility test, and stored into
* cmax/cmin if successful)
+ * options - bitmask of options. No values are currently recognized.
* crosscheck - if not InvalidSnapshot, also check old tuple against this
* wait - true if should wait for any conflicting update to commit/abort
*
@@ -1579,12 +1587,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, uint32 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
--3myajthupiacptbt
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v5-0003-Define-heap_insert-to-obey-tableam.h-option-bits-.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v4 1/2] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 6018dacf0f7..77560b22877 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 ab2e7fc1dfe..6cdd949f58d 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -287,6 +287,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,
@@ -558,17 +563,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1533,12 +1539,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)
+ uint32 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);
}
/*
@@ -1578,12 +1584,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, uint32 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
--qw4pfb7b6o5w4tnh
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v4-0002-Change-heapam.c-to-obey-tableam.h-option-bits-dir.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
* [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update
@ 2026-03-30 11:27 Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 989+ messages in thread
From: Álvaro Herrera @ 2026-03-30 11:27 UTC (permalink / raw)
The table_insert() method already has an equivalent argument, so this
makes sense just on consistency grounds, for future growth.
table_delete() can immediately use it to carry the 'changingPart'
boolean (which is arguably misplaced in the current API); for
table_update we don't have any options at present, but an upcoming patch
would add one.
Discussion: https://postgr.es/m/[email protected]
---
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 d34136d2e94..0645b2d5f58 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2862,8 +2862,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, uint32 options, Snapshot crosscheck,
+ bool wait, TM_FailureData *tmfd)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -2876,6 +2876,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;
@@ -3290,9 +3291,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:
@@ -3331,7 +3334,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, uint32 options, Snapshot crosscheck, bool wait,
TM_FailureData *tmfd, LockTupleMode *lockmode,
TU_UpdateIndexes *update_indexes)
{
@@ -4585,7 +4588,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 cdd153c6b6d..69debeff516 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -313,21 +313,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)
+ uint32 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, uint32 options pg_attribute_unused(),
+ Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
{
@@ -339,7 +341,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 86481d7c029..68ff0966f1c 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -320,9 +320,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)
{
@@ -369,7 +369,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 582bcc367c0..76728f08734 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;
+ uint32 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 f46c83e88f3..54067b828e4 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -382,13 +382,14 @@ extern void heap_multi_insert(Relation relation, TupleTableSlot **slots,
int ntuples, CommandId cid, uint32 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, uint32 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, uint32 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 57892152957..c3b4429d9b9 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -288,6 +288,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,
@@ -559,17 +564,18 @@ typedef struct TableAmRoutine
TM_Result (*tuple_delete) (Relation rel,
ItemPointer tid,
CommandId cid,
+ uint32 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,
+ uint32 options,
Snapshot snapshot,
Snapshot crosscheck,
bool wait,
@@ -1534,12 +1540,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)
+ uint32 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);
}
/*
@@ -1579,12 +1585,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, uint32 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
--qfkt2ktdpcfeypib
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="v48-0003-Rename-cluster.c-h-repack.c-h.patch"
^ permalink raw reply [nested|flat] 989+ messages in thread
end of thread, other threads:[~2026-03-30 11:27 UTC | newest]
Thread overview: 989+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15 09:19 Re: Retry Cached Remote Connections for postgres_fdw in case remote backend gets killed/goes away Fujii Masao <[email protected]>
2020-09-17 06:44 ` Bharath Rupireddy <[email protected]>
2020-09-17 16:50 ` Fujii Masao <[email protected]>
2020-09-21 03:44 ` Bharath Rupireddy <[email protected]>
2020-09-23 14:49 ` Fujii Masao <[email protected]>
2020-09-25 04:56 ` Bharath Rupireddy <[email protected]>
2020-09-25 09:51 ` Fujii Masao <[email protected]>
2020-09-25 12:19 ` Bharath Rupireddy <[email protected]>
2020-09-29 14:00 ` Fujii Masao <[email protected]>
2020-09-29 15:50 ` Bharath Rupireddy <[email protected]>
2020-09-29 16:31 ` Fujii Masao <[email protected]>
2020-09-30 12:02 ` Bharath Rupireddy <[email protected]>
2020-09-30 18:02 ` Fujii Masao <[email protected]>
2020-10-01 12:14 ` Bharath Rupireddy <[email protected]>
2020-10-01 14:39 ` Fujii Masao <[email protected]>
2020-10-01 15:46 ` Bharath Rupireddy <[email protected]>
2020-10-02 18:00 ` Fujii Masao <[email protected]>
2020-10-03 11:40 ` Bharath Rupireddy <[email protected]>
2020-10-05 04:15 ` Fujii Masao <[email protected]>
2020-10-05 11:32 ` Bharath Rupireddy <[email protected]>
2020-10-06 01:54 ` Fujii Masao <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v4 1/2] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v5 2/3] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
2026-03-30 11:27 [PATCH v48 2/7] Give 'options' parameter to table_delete/table_update Álvaro Herrera <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox