I have been looking at the planner's handling of subplans, and I see
something that I think is wrong, but I'm not quite certain. In
_make_subplan() in backend/optimizer/plan/subselect.c, there is the
code
/* make parParam list */ foreach(lst, plan->extParam) { Var *var = nth(lfirsti(lst),
PlannerParamVar);
if (var->varlevelsup == PlannerQueryLevel) node->parParam = lappendi(node->parParam, lfirsti(lst));
}
It looks to me like this code is supposed to find parameters that
reference the immediate parent plan level, as opposed to higher levels.
So, shouldn't it be looking for varlevelsup == 1, not PlannerQueryLevel?
For a first-level subplan, PlannerQueryLevel will be 1 at the time
this code runs, so the result is the same anyway. But I think it
does the wrong thing for more deeply nested subplans. Am I right?
regards, tom lane