Re: Allow batched insert during cross-partition updates

From: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, vignesh C <vignesh21(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>, Zhihong Yu <zyu(at)yugabyte(dot)com>, "gkokolatos(at)pm(dot)me" <gkokolatos(at)pm(dot)me>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Subject: Re: Allow batched insert during cross-partition updates
Date: 2022-12-06 09:48:54
Message-ID: CAPmGK15osRDrHZv+rChBnts_5VhAdrH=qs=+sVz4eXWu7x4O7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Amit-san,

On Tue, Mar 22, 2022 at 10:17 AM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> Rebased to fix a minor conflict with some recently committed
> nodeModifyTable.c changes.

Apologies for not having reviewed the patch. Here are some review comments:

* The patch conflicts with commit ffbb7e65a, so please update the
patch. (That commit would cause an API break, so I am planning to
apply a fix to HEAD as well [1].) That commit fixed the handling of
pending inserts, which I think would eliminate the need to do this:

* ExecModifyTable(), when inserting any remaining batched tuples,
must look at the correct set of ResultRelInfos that would've been
used by such inserts, because failing to do so would result in those
tuples not actually getting inserted. To fix, ExecModifyTable() is
now made to get the ResultRelInfos from the PartitionTupleRouting
data structure which contains the ResultRelInfo that would be used by
those internal inserts. To allow nodeModifyTable.c look inside
PartitionTupleRouting, its definition, which was previously local to
execPartition.c, is exposed via execPartition.h.

* In postgresGetForeignModifyBatchSize():

/*
- * Should never get called when the insert is being performed as part of a
- * row movement operation.
+ * Use the auxiliary state if any; see postgresBeginForeignInsert() for
+ * details on what it represents.
*/
- Assert(fmstate == NULL || fmstate->aux_fmstate == NULL);
+ if (fmstate != NULL && fmstate->aux_fmstate != NULL)
+ fmstate = fmstate->aux_fmstate;

I might be missing something, but I think we should leave the Assert
as-is, because we still disallow to move rows to another foreign-table
partition that is also an UPDATE subplan result relation, which means
that any fmstate should have fmstate->aux_fmstate=NULL.

* Also in that function:

- if (fmstate)
+ if (fmstate != NULL)

This is correct, but I would vote for leaving that as-is, to make
back-patching easy.

That is all I have for now. I will mark this as Waiting on Author.

Best regards,
Etsuro Fujita

[1] https://www.postgresql.org/message-id/CAPmGK17rmXEY3BL%3DAq71L8UZv5f-mz%3DuxJkz1kMnfSSY%2BpFe-A%40mail.gmail.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ronan Dunklau 2022-12-06 10:22:20 Re: Fix gin index cost estimation
Previous Message Alexander Pyhalov 2022-12-06 09:28:43 Re: Add semi-join pushdown to postgres_fdw