Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-12-03 Thread Tom Lane
Andrei Lepikhov writes: > Pardon the noise, but I'm curious why the optimiser must choose NestLoop > in the case of lateral reference. To pass down the current outer row's value of the lateral reference. > It would be nice to provide alternatives. Because now we have some > corner cases. That

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-12-03 Thread Andrei Lepikhov
On 11/29/24 05:33, Tom Lane wrote: Avoid mislabeling of lateral references when pulling up a subquery. If we are pulling up a subquery that's under an outer join, and the subquery's target list contains a strict expression that uses both a subquery variable and a lateral-reference variable, it's

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-29 Thread Tom Lane
Richard Guo writes: > This patch can also simplify my other patch, which is to avoid > unnecessary wrapping for plain Vars/PHVs. We can check the new > nullingrel_info to see if the nullingrels of the subquery RTE are a > subset of the nullingrels of the lateral referenced rel, to determine > if

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-29 Thread Richard Guo
On Sat, Nov 30, 2024 at 6:31 AM Tom Lane wrote: > I wrote: > > The ideas I'd been toying with last night involved a pre-scan over > > the join tree to calculate the potential nullingrels of each leaf RTE > > (same idea as RelOptInfo.nulling_relids, but of course we don't have > > any RelOptInfos y

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-29 Thread Tom Lane
I wrote: > The ideas I'd been toying with last night involved a pre-scan over > the join tree to calculate the potential nullingrels of each leaf RTE > (same idea as RelOptInfo.nulling_relids, but of course we don't have > any RelOptInfos yet). That seems painful though because we'd have to > upda

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-29 Thread Tom Lane
Richard Guo writes: > I spent some time looking into this issue. Thanks for looking at it! > First of all, the lateral references cannot be outside of the lowest > outer join above the subquery; otherwise, is_simple_subquery() would > consider the subquery not eligible for pull-up. Yeah. While

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-29 Thread Richard Guo
On Fri, Nov 29, 2024 at 10:44 AM Tom Lane wrote: > Richard Guo writes: > > On Fri, Nov 29, 2024 at 7:33 AM Tom Lane wrote: > >> It seems to be sufficient to just not mark lateral > >> references at all in this case. (I have a nagging feeling that more > >> complexity may be needed in cases wher

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-28 Thread Tom Lane
Richard Guo writes: > On Fri, Nov 29, 2024 at 7:33 AM Tom Lane wrote: >> It seems to be sufficient to just not mark lateral >> references at all in this case. (I have a nagging feeling that more >> complexity may be needed in cases where there are several levels of >> outer join, but some attemp

Re: pgsql: Avoid mislabeling of lateral references when pulling up a subque

2024-11-28 Thread Richard Guo
On Fri, Nov 29, 2024 at 7:33 AM Tom Lane wrote: > It seems to be sufficient to just not mark lateral > references at all in this case. (I have a nagging feeling that more > complexity may be needed in cases where there are several levels of > outer join, but some attempts to break it with that di