Skip to content

Commit 79edb2b

Browse files
committed
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.
1 parent 054219c commit 79edb2b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/backend/utils/adt/selfuncs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4382,6 +4382,17 @@ examine_simple_variable(PlannerInfo *root, Var *var,
43824382
/* Subquery should have been planned already */
43834383
Assert(rel->subroot && IsA(rel->subroot, PlannerInfo));
43844384

4385+
/*
4386+
* Switch our attention to the subquery as mangled by the planner.
4387+
* It was okay to look at the pre-planning version for the tests
4388+
* above, but now we need a Var that will refer to the subroot's
4389+
* live RelOptInfos. For instance, if any subquery pullup happened
4390+
* during planning, Vars in the targetlist might have gotten replaced,
4391+
* and we need to see the replacement expressions.
4392+
*/
4393+
subquery = rel->subroot->parse;
4394+
Assert(IsA(subquery, Query));
4395+
43854396
/* Get the subquery output expression referenced by the upper Var */
43864397
ste = get_tle_by_resno(subquery->targetList, var->varattno);
43874398
if (ste == NULL || ste->resjunk)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy