HI Richard
> Thanks for reporting this and tracking it down to lateral PHVs. > > Between the two approaches you mentioned, I'm personally more inclined > towards your second thought (checking lateral_referencers). > > My slight concern with switching to required_relids is that > required_relids and nulling_relids serve slightly different purposes > conceptually. While checking required_relids happens to catch the issue > here, I wonder if that might be an indirect effect of how PHV's ph_eval_at > tracks outer joins. For instance, if s were involved in an inner join > instead of a left join, rel->nulling_relids would be empty, but we > probably still wouldn't want to push down a qual that references s's > lateral referencers into the child relations. > > In that sense, checking rel->lateral_referencers seems to capture the root > of the problem more naturally: the qual references something (ss) that > topologically depends on s, so it shouldn't be pushed down to s's child > relations in the first place. That also aligns very well with the > reasoning already used in join_clause_is_movable_to(). > > So perhaps something like this would be a bit more robust: > > diff > - if (!bms_overlap(rinfo->clause_relids, rel->nulling_relids)) > + if (!bms_overlap(rinfo->clause_relids, rel->nulling_relids) && > + !bms_overlap(rinfo->clause_relids, rel->lateral_referencers)) > > What do you think? > > > Regards
