Re: postgres_fdw: batch inserts vs. before row triggers

2022-12-07 Thread Etsuro Fujita
On Fri, Dec 2, 2022 at 4:54 PM Etsuro Fujita wrote: > On Sun, Nov 27, 2022 at 12:11 AM Tom Lane wrote: > > OK, as long as there's a reason for doing it that way, it's OK > > by me. I don't think that adding a field at the end of EState > > is an ABI problem. > > > > We have to do something else

Re: postgres_fdw: batch inserts vs. before row triggers

2022-12-01 Thread Etsuro Fujita
On Sun, Nov 27, 2022 at 12:11 AM Tom Lane wrote: > Etsuro Fujita writes: > > On Sat, Nov 26, 2022 at 1:57 AM Tom Lane wrote: > >> Couldn't we add the field to ModifyTableState, instead? > > > We could probably do so, but I thought having a global list would be > > more efficient to handle pendin

Re: postgres_fdw: batch inserts vs. before row triggers

2022-11-26 Thread Tom Lane
Etsuro Fujita writes: > On Sat, Nov 26, 2022 at 1:57 AM Tom Lane wrote: >> Couldn't we add the field to ModifyTableState, instead? > We could probably do so, but I thought having a global list would be > more efficient to handle pending buffered inserts than that. OK, as long as there's a reaso

Re: postgres_fdw: batch inserts vs. before row triggers

2022-11-26 Thread Etsuro Fujita
On Sat, Nov 26, 2022 at 1:57 AM Tom Lane wrote: > I don't think the committed patch is acceptable at all, at least > not in the back branches, because it creates a severe ABI break. > Specifically, by adding a field to ResultRelInfo you have changed > the array stride of es_result_relations, and t

Re: postgres_fdw: batch inserts vs. before row triggers

2022-11-25 Thread Tom Lane
Etsuro Fujita writes: > I have committed the patch. Apologies for not having paid attention to this thread, but ... I don't think the committed patch is acceptable at all, at least not in the back branches, because it creates a severe ABI break. Specifically, by adding a field to ResultRelInfo y

Re: postgres_fdw: batch inserts vs. before row triggers

2022-11-25 Thread Etsuro Fujita
On Thu, Nov 24, 2022 at 8:19 PM Etsuro Fujita wrote: > Here is an updated patch. In the attached, I added an assertion to > ExecInsert(). Also, I tweaked comments and test cases a little bit, > for consistency. Also, I noticed a copy-and-pasteo in a comment in > ExecBatchInsert(), so I fixed it

Re: postgres_fdw: batch inserts vs. before row triggers

2022-11-24 Thread Etsuro Fujita
On Fri, Nov 18, 2022 at 8:46 PM Etsuro Fujita wrote: > Attached is a patch for fixing these issues. Here is an updated patch. In the attached, I added an assertion to ExecInsert(). Also, I tweaked comments and test cases a little bit, for consistency. Also, I noticed a copy-and-pasteo in a com

Re: postgres_fdw: batch inserts vs. before row triggers

2022-11-18 Thread Etsuro Fujita
Hi, While working on something else, I notice some more oddities. Here is an example: create extension postgres_fdw; create server loopback foreign data wrapper postgres_fdw options (dbname 'postgres'); create user mapping for current_user server loopback; create table t1 (a text, b int); create

Re: postgres_fdw: batch inserts vs. before row triggers

2022-08-05 Thread Etsuro Fujita
On Wed, Aug 3, 2022 at 2:24 PM Etsuro Fujita wrote: > To fix, I modified postgresGetForeignModifyBatchSize() to disable > batch insert when there are any such constraints, like when there are > any AFTER ROW triggers on the foreign table. Attached is a patch for > that. > > If there are no object

Re: postgres_fdw: batch inserts vs. before row triggers

2022-08-03 Thread Matthias van de Meent
On Wed, 3 Aug 2022 at 23:57, Tom Lane wrote: > > Matthias van de Meent writes: > > I don't have a current version of the SQL spec, but one preliminary > > version of SQL:2012 I retrieved via the wiki details that all BEFORE > > triggers on INSERT/UPDATE/DELETE statements are all executed before >

Re: postgres_fdw: batch inserts vs. before row triggers

2022-08-03 Thread Tom Lane
Matthias van de Meent writes: > I don't have a current version of the SQL spec, but one preliminary > version of SQL:2012 I retrieved via the wiki details that all BEFORE > triggers on INSERT/UPDATE/DELETE statements are all executed before > _any_ of that statements' affected data is modified. >

Re: postgres_fdw: batch inserts vs. before row triggers

2022-08-03 Thread Matthias van de Meent
On Tue, 19 Apr 2022 at 14:00, Tomas Vondra wrote: > > On 4/19/22 11:16, Etsuro Fujita wrote: > > On Sun, Apr 17, 2022 at 6:20 PM Etsuro Fujita > > wrote: > >> Here > >> is an example using HEAD: > >> > >> create extension postgres_fdw; > >> create server loopback foreign data wrapper postgres_fd

Re: postgres_fdw: batch inserts vs. before row triggers

2022-08-02 Thread Etsuro Fujita
Hi, Another thing I noticed while working on the "Fast COPY FROM based on batch insert" patch is: batch inserts vs. WITH CHECK OPTION constraints from parent views. Here is an example on a normal build producing incorrect results. CREATE TABLE base_tbl (a int, b int); CREATE FUNCTION row_before_

Re: postgres_fdw: batch inserts vs. before row triggers

2022-04-20 Thread Etsuro Fujita
Hi, On Tue, Apr 19, 2022 at 9:00 PM Tomas Vondra wrote: > On 4/19/22 11:16, Etsuro Fujita wrote: > > On Sun, Apr 17, 2022 at 6:20 PM Etsuro Fujita > > wrote: > >> So I think we should disable batch insert in such cases, just as we > >> disable multi insert when there are any before row triggers

Re: postgres_fdw: batch inserts vs. before row triggers

2022-04-19 Thread Tomas Vondra
On 4/19/22 11:16, Etsuro Fujita wrote: > On Sun, Apr 17, 2022 at 6:20 PM Etsuro Fujita wrote: >> Here >> is an example using HEAD: >> >> create extension postgres_fdw; >> create server loopback foreign data wrapper postgres_fdw options >> (dbname 'postgres'); >> create user mapping for current_

Re: postgres_fdw: batch inserts vs. before row triggers

2022-04-19 Thread Etsuro Fujita
On Sun, Apr 17, 2022 at 6:20 PM Etsuro Fujita wrote: > Here > is an example using HEAD: > > create extension postgres_fdw; > create server loopback foreign data wrapper postgres_fdw options > (dbname 'postgres'); > create user mapping for current_user server loopback; > create table t (a int); > c

postgres_fdw: batch inserts vs. before row triggers

2022-04-17 Thread Etsuro Fujita
Hi, (I added Tomas in CC:.) One thing I noticed while reviewing the patch for fast copying into foreign tables/partitions using batch insert [1] is that in postgres_fdw we allow batch-inserting into foreign tables/partitions with before row triggers, but such triggers might query the target table/