Re: A new strategy for pull-up correlated ANY_SUBLINK

2024-07-03 Thread Andrei Lepikhov
On 7/1/24 16:17, Andrei Lepikhov wrote: On 10/12/23 14:52, Andy Fan wrote: Here the sublink can't be pulled up because of its reference to the  LHS of left join, the original logic is that no matter the 'b.t in ..' returns the true or false,  the rows in LHS will be returned.  If we pull it up

Re: A new strategy for pull-up correlated ANY_SUBLINK

2024-07-01 Thread Andrei Lepikhov
On 10/12/23 14:52, Andy Fan wrote: Here the sublink can't be pulled up because of its reference to the  LHS of left join, the original logic is that no matter the 'b.t in ..' returns the true or false,  the rows in LHS will be returned.  If we pull it up to LHS, some rows in LHS will be filtered

Re: A new strategy for pull-up correlated ANY_SUBLINK

2024-02-15 Thread Andy Fan
Hi Alexander, > Hi! > >> If the changes of Alena are ok, can you merge the changes and post an >> updated version so that CFBot can apply the patch and verify the >> changes. As currently CFBot is trying to apply only Alena's changes >> and failing with the following at [1]: > > I think this is

Re: A new strategy for pull-up correlated ANY_SUBLINK

2024-02-13 Thread Alexander Korotkov
Hi! > If the changes of Alena are ok, can you merge the changes and post an > updated version so that CFBot can apply the patch and verify the > changes. As currently CFBot is trying to apply only Alena's changes > and failing with the following at [1]: I think this is a very nice and pretty simp

Re: A new strategy for pull-up correlated ANY_SUBLINK

2024-01-26 Thread vignesh C
On Fri, 13 Oct 2023 at 14:09, Alena Rybakina wrote: > > On 13.10.2023 10:04, Andy Fan wrote: >> >> It seems to me that the expressions "=" and "IN" are equivalent here due to >> the fact that the aggregated subquery returns only one value, and the result >> with the "IN" operation can be conside

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-10-13 Thread Alena Rybakina
On 13.10.2023 10:04, Andy Fan wrote: It seems to me that the expressions "=" and "IN" are equivalent here due to the fact that the aggregated subquery returns only one value, and the result with the "IN" operation can be considered as the intersection of elements on the left and

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-10-13 Thread Andy Fan
Hi Tom, Would you like to have a look at this? The change is not big and the optimization has also been asked for many times. The attached is the v5 version and I also try my best to write a good commit message. Here is the commit fest entry: https://commitfest.postgresql.org/45/4268/ v5-000

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-10-13 Thread Andy Fan
> > It seems to me that the expressions "=" and "IN" are equivalent here due > to the fact that the aggregated subquery returns only one value, and the > result with the "IN" operation can be considered as the intersection of > elements on the left and right. In this query, we have some kind of set

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-10-12 Thread Alena Rybakina
On 12.10.2023 10:52, Andy Fan wrote: Unfortunately, I found a request when sublink did not pull-up, as in the examples above. I couldn't quite figure out why. I'm not sure what you mean with the "above", I guess it should be the "below"? Yes, you are right) explain (anal

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-10-12 Thread Andy Fan
Hi Alena, On Thu, Oct 12, 2023 at 5:01 AM Alena Rybakina wrote: > Hi! > > I reviewed your patch and it was interesting for me! > > Thank you for the explanation. It was really informative for me! > Thanks for your interest in this, and I am glad to know it is informative. > Unfortunately, I fo

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-10-11 Thread Alena Rybakina
Hi! I reviewed your patch and it was interesting for me! Thank you for the explanation. It was really informative for me! I think we need the restriction and that should be enough for this feature . Given the query Richard provided before: explain select * from tenk1 A where exists (select 1

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-04-05 Thread Andy Fan
Hi Tom: Sorry for the delayed response! I think my knowledge has been refreshed for this discussion. > One thing I'm not at all clear about is whether we need to restrict > the optimization so that it doesn't occur if the subquery contains > outer references falling outside available_rels. I

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-02-13 Thread Andy Fan
Hi All: Sorry for the delay. Once I saw Tom's reply on Nov 15, I tried his suggestion about "whether we need to restrict the optimization so that it doesn't occur if the subquery contains outer references falling outside available_rels. " quickly, I'm sure such a restriction can fix the bad

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-01-31 Thread vignesh C
On Fri, 6 Jan 2023 at 11:46, vignesh C wrote: > > On Sun, 13 Nov 2022 at 04:15, Tom Lane wrote: > > > > Andy Fan writes: > > > In the past we pull-up the ANY-sublink with 2 steps, the first step is to > > > pull up the sublink as a subquery, and the next step is to pull up the > > > subquery if

Re: A new strategy for pull-up correlated ANY_SUBLINK

2023-01-05 Thread vignesh C
On Sun, 13 Nov 2022 at 04:15, Tom Lane wrote: > > Andy Fan writes: > > In the past we pull-up the ANY-sublink with 2 steps, the first step is to > > pull up the sublink as a subquery, and the next step is to pull up the > > subquery if it is allowed. The benefits of this method are obvious, > >

Re: A new strategy for pull-up correlated ANY_SUBLINK

2022-11-14 Thread Richard Guo
On Sun, Nov 13, 2022 at 6:45 AM Tom Lane wrote: > Looking again at that contain_vars_of_level restriction, I think the > reason for it was just to avoid making a FROM subquery that has outer > references, and the reason we needed to avoid that was merely that we > didn't have LATERAL at the time.

Re: A new strategy for pull-up correlated ANY_SUBLINK

2022-11-12 Thread Tom Lane
Andy Fan writes: > In the past we pull-up the ANY-sublink with 2 steps, the first step is to > pull up the sublink as a subquery, and the next step is to pull up the > subquery if it is allowed. The benefits of this method are obvious, > pulling up the subquery has more requirements, even if we c

Re: A new strategy for pull-up correlated ANY_SUBLINK

2022-11-01 Thread Andy Fan
Hi Andrey: > > In this patch we distinguish the above case and try to pull-up it within > > one step if it is helpful, It looks to me that what we need to do is just > > transform it to EXIST-SUBLINK. > Maybe code [1] would be useful for your purposes/tests. > Looks like we are resolving the sam

Re: A new strategy for pull-up correlated ANY_SUBLINK

2022-11-01 Thread Andrey Lepikhov
On 2/11/2022 09:02, Andy Fan wrote: In the past we pull-up the ANY-sublink with 2 steps, the first step is to pull up the sublink as a subquery, and the next step is to pull up the subquery if it is allowed.  The benefits of this method are obvious, pulling up the subquery has more requirements,

A new strategy for pull-up correlated ANY_SUBLINK

2022-11-01 Thread Andy Fan
In the past we pull-up the ANY-sublink with 2 steps, the first step is to pull up the sublink as a subquery, and the next step is to pull up the subquery if it is allowed. The benefits of this method are obvious, pulling up the subquery has more requirements, even if we can just finish the first s