About displaying NestLoopParam

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: About displaying NestLoopParam
Date: 2022-09-16 09:59:11
Message-ID: CAMbWs4-YSOcQXAagJetP95cAeZPqzOy5kM5yijG0PVW5ztRb4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2022-09-16 11:28:29 Re: Switching XLog source from archive to streaming when primary available
Previous Message Maxim Orlov 2022-09-16 08:59:20 Re: Add 64-bit XIDs into PostgreSQL 15