Re: Add proper planner support for ORDER BY / DISTINCT aggregates
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Ronan Dunklau <ronan.dunklau@aiven.io>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>,
Ranier Vilela <ranier.vf@gmail.com>
Date: 2022-07-27T03:16:36Z
Lists: pgsql-hackers
On Wed, Jul 27, 2022 at 6:46 AM David Rowley <dgrowleyml@gmail.com> wrote: > On Tue, 26 Jul 2022 at 19:39, Richard Guo <guofenglinux@gmail.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
Commits
-
Don't presort ORDER BY/DISTINCT Aggrefs with volatile functions
- da5800d5fa63 16.0 landed
-
Add enable_presorted_aggregate GUC
- 3226f47282a0 16.0 landed
-
Remove pessimistic cost penalization from Incremental Sort
- 4a29eabd1d91 16.0 landed
-
Fix hypothetical problem passing the wrong GROUP BY pathkeys
- af7d270dd3c7 16.0 landed
-
Remove unused fields from ExprEvalStep
- 9fc1776dda9f 16.0 landed
-
Improve performance of ORDER BY / DISTINCT aggregates
- 1349d2790bf4 16.0 landed
-
Refactor function parse_subscription_options.
- 8aafb0261675 15.0 cited