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