I have a question about displaying NestLoopParam. In the plan below,
# explain (costs off)
select * from a, lateral (select sum(i) as i from b where exists (select sum(c.i) from c where c.j = a.j and c.i = b.i) ) ss where a.i = ss.i;
QUERY PLAN
--------------------------------------------------------------------
Nested Loop
-> Seq Scan on a
-> Subquery Scan on ss
Filter: (a.i = ss.i)
-> Aggregate
-> Seq Scan on b
Filter: (SubPlan 1)
SubPlan 1
-> Aggregate
-> Seq Scan on c
Filter: ((j = $0) AND (i = b.i))
(11 rows)
There are three Params. Param 0 (a.j) and param 2 (a.i) are from
nestParams of the NestLoop. Param 1 (b.i) is from parParam of the
SubPlan. As we can see, param 1 and param 2 are displayed as the
corresponding expressions, while param 0 is displayed as $0.
I'm not saying this is a bug, but just curious why param 0 cannot be
displayed as the referenced expression. And I find the reason is that in
function find_param_referent(), we have the 'in_same_plan_level' flag
controlling that if we have emerged from a subplan, i.e. not the same
plan level any more, we would not look further for the matching
NestLoopParam. Param 0 suits this situation.
And there is a comment there also saying,
/*
* NestLoops transmit params to their inner child only; also, once
* we've crawled up out of a subplan, this couldn't possibly be
* the right match.
*/
My question is why is that?
Thanks
Richard