Re: POC: GROUP BY optimization
Alexander Korotkov <aekorotkov@gmail.com>
From: Alexander Korotkov <aekorotkov@gmail.com>
To: Andrei Lepikhov <a.lepikhov@postgrespro.ru>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Richard Guo <guofenglinux@gmail.com>, Pavel Borisov <pashkin.elfe@gmail.com>, vignesh C <vignesh21@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>, Tomas Vondra <tomas.vondra@enterprisedb.com>,
Teodor Sigaev <teodor@sigaev.ru>, David Rowley <dgrowleyml@gmail.com>, "a.rybakina" <a.rybakina@postgrespro.ru>
Date: 2024-04-18T10:57:41Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Restore preprocess_groupclause()
- 505c008ca37c 17.0 landed
-
Rename PathKeyInfo to GroupByOrdering
- 0c1af2c35c7b 17.0 landed
-
Add invariants check to get_useful_group_keys_orderings()
- 91143c03d4ca 17.0 landed
-
Fix asymmetry in setting EquivalenceClass.ec_sortref
- 199012a3d844 17.0 landed
-
Multiple revisions to the GROUP BY reordering tests
- 874d817baa16 17.0 landed
-
Get rid of pg_class usage in SJE regression tests
- e1b7fde418f2 17.0 landed
-
Rename index "abc" in aggregates.sql
- b91f91870828 17.0 landed
-
Explore alternative orderings of group-by pathkeys during optimization.
- 0452b461bc40 17.0 landed
-
Generalize the common code of adding sort before processing of grouping
- 7ab80ac1caf9 17.0 landed
-
Fix out-dated comment in preprocess_groupclause()
- f6c70b81802a 15.0 landed
- 78a9af1a2764 16.0 landed
-
Force parallelism in partition_aggregate
- 2fe6b2a806f2 16.0 landed
- 01474f56981a 15.0 landed
-
Optimize order of GROUP BY keys
- db0d67db2401 15.0 landed
Hi, Andrei! On Thu, Apr 18, 2024 at 11:54 AM Andrei Lepikhov <a.lepikhov@postgrespro.ru> wrote: > On 4/12/24 06:44, Tom Lane wrote: > > * Speaking of pathnodes.h, PathKeyInfo is a pretty uninformative node > > type name, and the comments provided for it are not going to educate > > anybody. What is the "association" between the pathkeys and clauses? > > I guess the clauses are supposed to be SortGroupClauses, but not all > > pathkeys match up to SortGroupClauses, so what then? This is very > > underspecified, and fuzzy thinking about data structures tends to lead > > to bugs. > I'm not the best in English documentation and naming style. So, feel > free to check my version. > > > > So I'm quite afraid that there are still bugs lurking here. > > What's more, given that the plans this patch makes apparently > > seldom win when you don't put a thumb on the scales, it might > > take a very long time to isolate those bugs. If the patch > > produces a faulty plan (e.g. not sorted properly) we'd never > > notice if that plan isn't chosen, and even if it is chosen > > it probably wouldn't produce anything as obviously wrong as > > a crash. > I added checkings on the proper order of pathkeys and clauses. > If you really care about that, we should spend additional time and > rewrite the code to generate an order of clauses somewhere in the plan > creation phase. For example, during the create_group_plan call, we could > use the processed_groupClause list, cycle through subpath->pathkeys, set > the order, and detect whether the pathkeys list corresponds to the > group-by or is enough to build a grouping plan. > Anyway, make this part of code more resistant to blunders is another story. Thank you for the fixes you've proposed. I didn't look much into details yet, but I think the main concern Tom expressed in [1] is whether the feature is reasonable at all. I think at this stage the most important thing is to come up with convincing examples showing how huge performance benefits it could cause. I will return to this later today and will try to provide some convincing examples. Links 1. https://www.postgresql.org/message-id/266850.1712879082%40sss.pgh.pa.us ------ Regards, Alexander Korotkov