aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/relnode.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2024-01-08 11:48:44 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2024-01-08 11:48:44 -0500
commit89b69db82adf742cadc36ee9a365cf47a632cdb0 (patch)
treef923f0e4c3f988f6cbe7e4c179c38d606f459fb6 /src/backend/optimizer/util/relnode.c
parentbea18b1c949145ba2ca79d4765dba3cc9494a480 (diff)
downloadpostgresql-89b69db82adf742cadc36ee9a365cf47a632cdb0.tar.gz
postgresql-89b69db82adf742cadc36ee9a365cf47a632cdb0.zip
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
Diffstat (limited to 'src/backend/optimizer/util/relnode.c')
-rw-r--r--src/backend/optimizer/util/relnode.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index 5a9ce44532d..22d01cef5b3 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -421,6 +421,19 @@ find_base_rel(PlannerInfo *root, int relid)
}
/*
+ * find_base_rel_noerr
+ * Find a base or otherrel relation entry, returning NULL if there's none
+ */
+RelOptInfo *
+find_base_rel_noerr(PlannerInfo *root, int relid)
+{
+ /* use an unsigned comparison to prevent negative array element access */
+ if ((uint32) relid < (uint32) root->simple_rel_array_size)
+ return root->simple_rel_array[relid];
+ return NULL;
+}
+
+/*
* find_base_rel_ignore_join
* Find a base or otherrel relation entry, which must already exist.
*