Re: Add proper planner support for ORDER BY / DISTINCT aggregates

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Ronan Dunklau <ronan(dot)dunklau(at)aiven(dot)io>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Subject: Re: Add proper planner support for ORDER BY / DISTINCT aggregates
Date: 2022-07-27 03:16:36
Message-ID: CAMbWs49Xw1Sb4KOZx6CMGBjiCNvGCcAyXkwWRGNZivyYv2fGMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 27, 2022 at 6:46 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:

> On Tue, 26 Jul 2022 at 19:39, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> > Also I'm wondering if it's possible to take into consideration the
> > ordering indicated by existing indexes when determining the pathkeys. So
> > that for the query below we can avoid the Incremental Sort node if we
> > consider that there is an index on t(a, c):
> >
> > # explain (costs off) select max(b order by b), max(c order by c) from t
> group by a;
> > QUERY PLAN
> > ---------------------------------------------
> > GroupAggregate
> > Group Key: a
> > -> Incremental Sort
> > Sort Key: a, b
> > Presorted Key: a
> > -> Index Scan using t_a_c_idx on t
> > (6 rows)
>
> That would be nice but I'm not going to add anything to this patch
> which does anything like that. I think the patch, as it is, is a good
> meaningful step forward to improve the performance of ordered
> aggregates.

Concur with that.

> There are other things in the planner that could gain from what you
> talk about. For example, choosing the evaluation order of WindowFuncs.
> Perhaps it would be better to try to tackle those two problems
> together rather than try to sneak something half-baked along with this
> patch.

That makes sense. The patch looks in a good shape to me in this part.

Thanks
Richard

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2022-07-27 03:17:46 Re: Refactor to make use of a common function for GetSubscriptionRelations and GetSubscriptionNotReadyRelations.
Previous Message Amit Langote 2022-07-27 03:14:10 Re: ExecRTCheckPerms() and many prunable partitions