From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow examine_simple_variable() to work on INSERT RETURNING Vars
Date: Mon, 08 Jan 2024 16:48:49 +0000
Message-ID: <E1rMsnx-000Udf-CF@gemulon.postgresql.org> (raw)
Allow examine_simple_variable() to work on INSERT RETURNING Vars.
Since commit 599b33b94, this function assumed that every RTE_RELATION
RangeTblEntry would have an associated RelOptInfo. But that's not so:
we only build RelOptInfos for relations that are scanned by the query.
In particular the target of an INSERT won't have one, so that Vars
appearing in an INSERT ... RETURNING list will not have an associated
RelOptInfo. This apparently wasn't a problem before commit f7816aec2
taught examine_simple_variable() to drill down into CTEs containing
INSERT RETURNING, but it is now.
To fix, add a fallback code path that gets the userid to use directly
from the RTEPermissionInfo associated with the RTE. (Sadly, we must
have two code paths, because not every RTE has a RTEPermissionInfo
either.)
Per report from Alexander Lakhin. No back-patch, since the case is
apparently unreachable before f7816aec2.
Discussion: https://postgr.es/m/608a4886-6c60-0f9e-97d5-591256bd4150@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/89b69db82adf742cadc36ee9a365cf47a632cdb0
Modified Files
--------------
src/backend/optimizer/util/relnode.c | 13 +++++++++++++
src/backend/utils/adt/selfuncs.c | 24 +++++++++++++++++++-----
src/include/optimizer/pathnode.h | 1 +
src/test/regress/expected/with.out | 18 ++++++++++++++++++
src/test/regress/sql/with.sql | 5 +++++
5 files changed, 56 insertions(+), 5 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 using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Allow examine_simple_variable() to work on INSERT RETURNING Vars
In-Reply-To: <E1rMsnx-000Udf-CF@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