pgsql: Fix handling of pending inserts in nodeModifyTable.c.

From: Etsuro Fujita <efujita(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix handling of pending inserts in nodeModifyTable.c.
Date: 2022-11-25 08:54:39
Message-ID: E1oyUTm-000jye-6f@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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_15_STABLE

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

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 | 96 ++++++++++++++-----
src/include/nodes/execnodes.h | 9 ++
7 files changed, 302 insertions(+), 21 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2022-11-25 10:59:06 pgsql: doc: Re-order sections of "28.4. Progress Reporting"
Previous Message Michael Paquier 2022-11-25 07:44:27 pgsql: Skip TAP test for peer authentication if there are no unix-domai