From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Change mechanism to set up source targetlist in MERGE
Date: Tue, 12 Apr 2022 07:48:11 +0000
Message-ID: <E1neBFz-0008qw-76@gemulon.postgresql.org> (raw)
Change mechanism to set up source targetlist in MERGE
We were setting MERGE source subplan's targetlist by expanding the
individual attributes of the source relation completely, early in the
parse analysis phase. This failed to work when the condition of an
action included a whole-row reference, causing setrefs.c to error out
with
ERROR: variable not found in subplan target lists
because at that point there is nothing to resolve the whole-row
reference with. We can fix this by having preprocess_targetlist expand
the source targetlist for Vars required from the source rel by all
actions. Moreover, by using this expansion mechanism we can do away
with the targetlist expansion in transformMergeStmt, which is good
because then we no longer pull in columns that aren't needed for
anything.
Add a test case for the problem.
While at it, remove some redundant code in preprocess_targetlist():
MERGE was doing separately what is already being done for UPDATE/DELETE,
so we can just rely on the latter and remove the former. (The handling
of inherited rels was different for MERGE, but that was a no-longer-
necessary hack.)
Fix outdated, related comments for fix_join_expr also.
Author: Richard Guo <guofenglinux@gmail.com>
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reported-by: Joe Wildish <joe@lateraljoin.com>
Discussion: https://postgr.es/m/fab3b90a-914d-46a9-beb0-df011ee39ee5@www.fastmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ce4f46fdc814eb1b704d81640f6d8f03625d0f53
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 7 +++-
src/backend/optimizer/prep/preptlist.c | 63 ++++++++++++++++++++++++----------
src/backend/parser/parse_merge.c | 9 ++---
src/test/regress/expected/merge.out | 13 +++++++
src/test/regress/expected/with.out | 6 ++--
src/test/regress/sql/merge.sql | 9 +++++
6 files changed, 80 insertions(+), 27 deletions(-)
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: alvherre@alvh.no-ip.org
Subject: Re: pgsql: Change mechanism to set up source targetlist in MERGE
In-Reply-To: <E1neBFz-0008qw-76@gemulon.postgresql.org>
References: <E1neBFz-0008qw-76@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