Re: POC: GROUP BY optimization
Dmitry Dolgov <9erthalion6@gmail.com>
From: Dmitry Dolgov <9erthalion6@gmail.com>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Teodor Sigaev <teodor@sigaev.ru>,
Gavin Flower <GavinFlower@archidevsys.co.nz>, Andres Freund <andres@anarazel.de>, Michael Paquier <michael@paquier.xyz>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2019-05-03T20:28:21Z
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
Attachments
- v12-0001-Add-tests-for-group-by-optimization.patch (application/octet-stream) patch v12-0001
- v12-0002-Reorder-to-match-ORDER-BY-or-index.patch (application/octet-stream) patch v12-0002
- v12-0003-Reorder-by-values-distribution.patch (application/octet-stream) patch v12-0003
> On Tue, Apr 9, 2019 at 5:21 PM Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: > > So I personally would suggest to treat those patches as independent until > the very last moment, develop the costing improvements needed by each > of them, and then decide which of them are committable / in what order. I had the same idea, but judging from the questions, raised in this thread, it's quite hard to go with reordering based only on frequency of values. I hoped that the cost_sort improvement patch would be simple enough to incorporate it here, but of course it wasn't. Having an assumption, that the amount of work, required for performing sorting, depends only on the number of distinct groups and how costly it is to compare a values of this data type, I've ended up extracting get_width_multiplier and get_func_cost parts from cost_sort patch and including them into 0003-Reorder-by-values-distribution. This allows to take into account situations when we compare e.g. long strings or a custom data type with high procost for comparison (but I've used this values directly without any adjusting coefficients yet). > On Wed, Jun 13, 2018 at 6:41 PM Teodor Sigaev <teodor@sigaev.ru> wrote: > > > So that's a nice improvement, although I think we should also consider > > non-uniform distributions (using the per-column MCV lists). > > Could you clarify how to do that? Since I'm not familiar with this topic, I would like to ask the same question, how to do that and what are the advantages? > On Sat, Jun 16, 2018 at 5:59 PM Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: > > I still think we need to be careful when introducing new optimizations > in this area - reordering the grouping keys by ndistinct, ORDER BY or > whatever. In particular I don't think we should commit these patches > that may quite easily cause regressions, and then hope some hypothetical > future patch fixes the costing. I'm a bit concerned about this part of the discussion. There is an idea through the whole thread about avoiding the situation, when a user knows which order is better and we generate different one by mistake. From what I see right now even if all the objections would be addressed, there is a chance that some coefficients will be not good enough (e.g. width multiplier is based on an average width, or it can suddenly happen that all the compared string have some difference at the very beginning) and the chosen order will be not optimal. Does it mean that in any case the implementation of such optimization should provide a way to override it?