I ran into $subject while fixing a bug caused by lateral PHVs. create table t (a int);
select 1 from t t1 left join (select 1 as x union all select 2) s on true left join lateral (select s.x as y from t t2) ss on true left join t t3 on ss.y is null; ERROR: failed to apply nullingrels to a non-Var Commit 767c59895 made set_append_rel_size() skip join quals that came from above an outer join that can null the parent rel, by checking their clause_relids. But that doesn't catch a nulled reference to the parent rel that appears only within a PHV, since pull_varnos() only reports where the PHV is evaluated. Here ss.y is a PHV containing s.x, so the t3 join qual is not skipped. It seems to me that we should check required_relids instead here. - if (!bms_overlap(rinfo->clause_relids, rel->nulling_relids)) + if (!bms_overlap(rinfo->required_relids, rel->nulling_relids)) Or, maybe an alternative is to skip quals whose clause_relids overlap the rel's lateral_referencers, as join_clause_is_movable_to() does, but checking required_relids seems simpler to me. Thoughts? - Richard
