Re: [POC] Allow flattening of subquery with a link to upper query - Mailing list pgsql-hackers

From Andrei Lepikhov
Subject Re: [POC] Allow flattening of subquery with a link to upper query
Date
Msg-id 168e9426-f7dc-4942-bc99-d5c57e81e4c2@postgrespro.ru
Whole thread Raw
In response to Re: [POC] Allow flattening of subquery with a link to upper query  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
On 20/2/2024 17:43, David Rowley wrote:
> On Tue, 20 Feb 2024 at 22:57, Andrei Lepikhov <a.lepikhov@postgrespro.ru> wrote: 
> I agree that it would be nice to teach the planner how to do this, but
> I think it just has to be a cost-based decision.  Imagine how the
> transformed query would perform of pg_am had a billion rows and
> pg_class had 1 row. That's quite a costly hash table build to be
> probing it just once.
True, the origins of this work lie in foreign tables where such a query 
generates an even worse situation.

> I didn't follow the patch, but there was a patch to push aggregate
> function evaluation down [1].  I imagine this has the same problem as
> if you just blindly pushed and aggregate function evaluation as deep
> as you could evaluate all the aggregate's parameters and group by vars
> then you may end up aggregating far more than you need to as some join
> could eliminate the majority of the groups.  I think we'd need to come
> up with some way to have the planner consider these types of
> optimisations as alternatives to what happens today and only apply
> them when we estimate that they're cheaper.  Right now a Path has no
> ability to describe that it's performed GROUP BY.
Thanks for the link. We also ended up with the idea of an alternative 
subtree (inspired by the approach of AlternativeSubplan). Here, we just 
explain the current state of the pull-up sublink technique.

-- 
regards,
Andrei Lepikhov
Postgres Professional




pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: speed up a logical replica setup
Next
From: Dilip Kumar
Date:
Subject: Re: logical decoding and replication of sequences, take 2