pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Etsuro Fujita <efujita@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix handling of pending inserts in nodeModifyTable.c.
Date: Fri, 25 Nov 2022 08:54:39 +0000
Message-ID: <E1oyUTm-000jyh-7A@gemulon.postgresql.org> (raw)

Fix handling of pending inserts in nodeModifyTable.c.

Commit b663a4136, which allowed FDWs to INSERT rows in bulk, added to
nodeModifyTable.c code to flush pending inserts to the foreign-table
result relation(s) before completing processing of the ModifyTable node,
but the code failed to take into account the case where the INSERT query
has modifying CTEs, leading to incorrect results.

Also, that commit failed to flush pending inserts before firing BEFORE
ROW triggers so that rows are visible to such triggers.

In that commit we scanned through EState's
es_tuple_routing_result_relations or es_opened_result_relations list to
find the foreign-table result relations to which pending inserts are
flushed, but that would be inefficient in some cases.  So to fix, 1) add
a List member to EState to record the insert-pending result relations,
and 2) modify nodeModifyTable.c so that it adds the foreign-table result
relation to the list in ExecInsert() if appropriate, and flushes pending
inserts properly using the list where needed.

While here, fix a copy-and-pasteo in a comment in ExecBatchInsert(),
which was added by that commit.

Back-patch to v14 where that commit appeared.

Discussion: https://postgr.es/m/CAPmGK16qutyCmyJJzgQOhfBq%3DNoGDqTB6O0QBZTihrbqre%2BoxA%40mail.gmail.com

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e52245228ecf3a58b031c820332bc56478bb1ba2

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 123 +++++++++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql      |  86 +++++++++++++++++
src/backend/executor/execMain.c                |   1 +
src/backend/executor/execPartition.c           |   7 ++
src/backend/executor/execUtils.c               |   1 +
src/backend/executor/nodeModifyTable.c         |  92 +++++++++++++-----
src/include/nodes/execnodes.h                  |   9 ++
7 files changed, 298 insertions(+), 21 deletions(-)



view thread (3+ messages)

Message-ID: <E1oyUTm-000jyh-7A@gemulon.postgresql.org>
Permalink:  ../E1oyUTm-000jyh-7A@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oyUTm-000jyh-7A@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: efujita@postgresql.org
  Subject: Re: pgsql: Fix handling of pending inserts in nodeModifyTable.c.
  In-Reply-To: <E1oyUTm-000jyh-7A@gemulon.postgresql.org>
  References: <E1oyUTm-000jyh-7A@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox