Andrei Lepikhov <lepihov@gmail.com> writes:
> I just want to understand how your idea will work. The query_planner
> does the job for subqueries separately. If a query is transformed in
> some way (let's say, an unnecessary join is deleted), we need to change
> references in the parse tree of another subquery, or it will not find
> the reference at the moment of planning, right?
Don't see why. If we're separately planning a subquery, we would
not dare to change anything about its outputs, just as we would
not make a change that affects the topmost level's outputs. I don't
believe there's anything right now that requires a recursive
subquery_planner call to change the outer parsetree, and this idea
wouldn't affect that.
Now, subquery_planner does have side effects on the PlannerGlobal
struct, but that's planner-local data, not an input to the planner.
Maybe we would like to have some enforced contract about what
subquery_planner can and can't touch in the outer planner level's
data, but I'm not feeling a great need for that right now.
regards, tom lane