Unnecessary lateral dependencies implied by PHVs - Mailing list pgsql-hackers

From Richard Guo
Subject Unnecessary lateral dependencies implied by PHVs
Date
Msg-id CAMbWs4--Qy-nLq_Eq61_rsQ3JUYteNh2G8-GnDkt+Fsp_t_Wjw@mail.gmail.com
Whole thread Raw
Responses Re: Unnecessary lateral dependencies implied by PHVs
Re: Unnecessary lateral dependencies implied by PHVs
List pgsql-hackers
Hi hackers,

As we know when we pull up a simple subquery, if the subquery is within
the nullable side of an outer join, lateral references to non-nullable
items may have to be turned into PlaceHolderVars. I happened to wonder
what should we do about the PHVs if the outer join is reduced to inner
join afterwards. Should we unwrap the related PHVs? I'm asking because
PHVs may imply lateral dependencies which may make us have to use
nestloop join. As an example, consider

explain (costs off)
select * from a left join lateral (select a.i as ai, b.i as bi from b) ss on true where ss.bi = ss.ai;
        QUERY PLAN
---------------------------
 Nested Loop
   ->  Seq Scan on a
   ->  Seq Scan on b
         Filter: (i = a.i)
(4 rows)

Although the JOIN_LEFT has been reduced to JOIN_INNER, the lateral
reference implied by the PHV makes us have no choice but the nestloop
with parameterized inner path. Considering there is no index on b, this
plan is very inefficient.

Is there anything we can do to improve this situation?

Thanks
Richard

pgsql-hackers by date:

Previous
From: bt22nakamorit
Date:
Subject: Re: ps command does not show walsender's connected db
Next
From: Peter Smith
Date:
Subject: Re: Support logical replication of DDLs