aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2021-05-25 12:50:22 +1200
committerDavid Rowley <drowley@postgresql.org>2021-05-25 12:50:22 +1200
commitcba5c70b956810c61b3778f7041f92fbb8065acb (patch)
tree19632f4af0804aa1e7d48032a03abbc7c08d296b
parentc242baa4a831ac2e7dcaec85feb410aefa3a996e (diff)
downloadpostgresql-cba5c70b956810c61b3778f7041f92fbb8065acb.tar.gz
postgresql-cba5c70b956810c61b3778f7041f92fbb8065acb.zip
Fix setrefs.c code for Result Cache nodes
Result Cache, added in 9eacee2e6 neglected to properly adjust the plan references in setrefs.c. This could lead to the following error during EXPLAIN: ERROR: cannot decompile join alias var in plan tree Fix that. Bug: 17030 Reported-by: Hans Buschmann Discussion: https://postgr.es/m/17030-5844aecae42fe223@postgresql.org
-rw-r--r--src/backend/optimizer/plan/setrefs.c6
-rw-r--r--src/test/regress/expected/join.out26
2 files changed, 19 insertions, 13 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 9f40ed77e64..61ccfd300b3 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -756,6 +756,12 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
{
ResultCache *rcplan = (ResultCache *) plan;
+ /*
+ * Result Cache does not evaluate its targetlist. It just
+ * uses the same targetlist from its outer subnode.
+ */
+ set_dummy_tlist_references(plan, rtoffset);
+
rcplan->param_exprs = fix_scan_list(root, rcplan->param_exprs,
rtoffset,
NUM_EXEC_TLIST(plan));
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 86fd3907c53..fec0325e73e 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4216,8 +4216,8 @@ where t1.f1 = ss.f1;
QUERY PLAN
--------------------------------------------------
Nested Loop
- Output: t1.f1, i8.q1, i8.q2, q1, f1
- Join Filter: (t1.f1 = f1)
+ Output: t1.f1, i8.q1, i8.q2, (i8.q1), t2.f1
+ Join Filter: (t1.f1 = t2.f1)
-> Nested Loop Left Join
Output: t1.f1, i8.q1, i8.q2
-> Seq Scan on public.text_tbl t1
@@ -4228,7 +4228,7 @@ where t1.f1 = ss.f1;
Output: i8.q1, i8.q2
Filter: (i8.q2 = 123)
-> Result Cache
- Output: q1, f1
+ Output: (i8.q1), t2.f1
Cache Key: i8.q1
-> Limit
Output: (i8.q1), t2.f1
@@ -4255,13 +4255,13 @@ select * from
lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss1,
lateral (select ss1.* from text_tbl t3 limit 1) as ss2
where t1.f1 = ss2.f1;
- QUERY PLAN
---------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------
Nested Loop
- Output: t1.f1, i8.q1, i8.q2, q1, f1, q1, f1
- Join Filter: (t1.f1 = f1)
+ Output: t1.f1, i8.q1, i8.q2, (i8.q1), t2.f1, ((i8.q1)), (t2.f1)
+ Join Filter: (t1.f1 = (t2.f1))
-> Nested Loop
- Output: t1.f1, i8.q1, i8.q2, q1, f1
+ Output: t1.f1, i8.q1, i8.q2, (i8.q1), t2.f1
-> Nested Loop Left Join
Output: t1.f1, i8.q1, i8.q2
-> Seq Scan on public.text_tbl t1
@@ -4272,19 +4272,19 @@ where t1.f1 = ss2.f1;
Output: i8.q1, i8.q2
Filter: (i8.q2 = 123)
-> Result Cache
- Output: q1, f1
+ Output: (i8.q1), t2.f1
Cache Key: i8.q1
-> Limit
Output: (i8.q1), t2.f1
-> Seq Scan on public.text_tbl t2
Output: i8.q1, t2.f1
-> Result Cache
- Output: q1, f1
- Cache Key: q1, f1
+ Output: ((i8.q1)), (t2.f1)
+ Cache Key: (i8.q1), t2.f1
-> Limit
- Output: (q1), (f1)
+ Output: ((i8.q1)), (t2.f1)
-> Seq Scan on public.text_tbl t3
- Output: q1, f1
+ Output: (i8.q1), t2.f1
(28 rows)
select * from