aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-09-29 18:12:34 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-09-29 18:13:16 -0400
commit79edb2b1dc33166b576f51a8255a7614f748d9c9 (patch)
tree70892283cb8006ce6af93bf7eeb29de059020f19 /src/backend/utils/adt/selfuncs.c
parent054219c907a9fe668b2dac4134563b4f38e2b233 (diff)
downloadpostgresql-79edb2b1dc33166b576f51a8255a7614f748d9c9.tar.gz
postgresql-79edb2b1dc33166b576f51a8255a7614f748d9c9.zip
Fix recursion into previously planned sub-query in examine_simple_variable.
This code was looking at the sub-Query tree as seen in the parent query's RangeTblEntry; but that's the pristine parser output, and what we need to look at is the tree as it stands at the completion of planning. Otherwise we might pick up a Var that references a subquery that got flattened and hence has no RelOptInfo in the subroot. Per report from Peter Geoghegan.
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 3e846799563..8ceea820bdc 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4382,6 +4382,17 @@ examine_simple_variable(PlannerInfo *root, Var *var,
/* Subquery should have been planned already */
Assert(rel->subroot && IsA(rel->subroot, PlannerInfo));
+ /*
+ * Switch our attention to the subquery as mangled by the planner.
+ * It was okay to look at the pre-planning version for the tests
+ * above, but now we need a Var that will refer to the subroot's
+ * live RelOptInfos. For instance, if any subquery pullup happened
+ * during planning, Vars in the targetlist might have gotten replaced,
+ * and we need to see the replacement expressions.
+ */
+ subquery = rel->subroot->parse;
+ Assert(IsA(subquery, Query));
+
/* Get the subquery output expression referenced by the upper Var */
ste = get_tle_by_resno(subquery->targetList, var->varattno);
if (ste == NULL || ste->resjunk)