Re: [HACKERS] Partition-wise aggregation/grouping
Jeevan Chalke <jeevan.chalke@enterprisedb.com>
Attachments
- partition-wise-agg-v11.tar.gz (application/x-gzip)
On Wed, Jan 17, 2018 at 1:18 AM, Robert Haas <robertmhaas@gmail.com> wrote: > On Tue, Jan 16, 2018 at 3:56 AM, Jeevan Chalke > <jeevan.chalke@enterprisedb.com> wrote: > > I will make your suggested changes that is merge create_sort_agg_path() > and > > create_hash_agg_path(). Will name that function as > > create_sort_and_hash_agg_paths(). > > I suggest add_paths_to_grouping_rel() and > add_partial_paths_to_grouping_rel(), similar to what commit > c44c47a773bd9073012935a29b0264d95920412c did with > add_paths_to_append_rel(). > > > Oops. My mistake. Missed. We should loop over the input rel's pathlist. > > > > Yep. With above change, the logic is very similar except > > (1) isPartialAgg/can_sort case creates the partial paths and > > (2) finalization step is not needed at this stage. > > I'm not sure what you mean by #1. > I mean, in case of isPartialAgg=true, we need to create a partial aggregation path which has aggsplit=AGGSPLIT_INITIAL_SERIAL and should not perform finalization at this stage. And thus add_paths_to_grouping_rel() needs a flag to diffrentiate it. By adding that code chunk allows us to reuse same function in both the cases i.e full and partial aggregation. Attached patch with other review points fixed. > > I think it can be done by passing a flag to create_sort_agg_path() (or > new > > combo function) and making appropriate adjustments. Do you think > addition of > > this new flag should go in re-factoring patch or main PWA patch? > > I think re-factoring patch. > > I think the refactoring patch should move the existing code into a new > function without any changes, and then the main patch should add an > additional argument to that function that allows for either behavior. > > By the way, I'm also a bit concerned about this: > > + /* > + * For full aggregation, we are done with the partial > paths. Just > + * clear it out so that we don't try to create a > parallel plan over it. > + */ > + grouped_rel->partial_pathlist = NIL; > > I think that's being done for the same reason as mentioned at the > bottom of the current code for create_grouping_paths(). They are only > partially aggregated and wouldn't produce correct final results if > some other planning step -- create_ordered_paths, or the code that > sets up final_rel -- used them as if they had been fully agggregated. > I'm worried that there might be an analogous danger for partition-wise > aggregation -- that is, that the paths being inserted into the partial > pathlists of the aggregate child rels might get reused by some later > planning step which doesn't realize that the output they produce > doesn't quite match up with the rel to which they are attached. You > may have already taken care of that problem somehow, but we should > make sure that it's fully correct and clearly commented. I don't > immediately see why the isPartialAgg case should be any different from > the !isPartialAgg case. > Actually I needed this because in case of full aggregation we already build all final aggregation paths before performing Append operation. However, when we do append in add_paths_to_append_rel(), it thinks that partial_pathlist present in grouped_rel is finalized one exactly like you mentioned above and thus we need to clear it out. But yes, for safer side, I think once we done with partition-wise aggregation step, we need to again go through the partitioning chain and need to clear out all child grouped rel's partial_pathlist for the reason mentioned at the bottom of the current code for create_grouping_paths(). > > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > -- Jeevan Chalke Technical Architect, Product Development EnterpriseDB Corporation The Enterprise PostgreSQL Company
Commits
-
postgres_fdw: Push down partition-wise aggregation.
- 7e0d64c7a57e 11.0 landed
-
Remove 'target' from GroupPathExtraData.
- c1de1a3a8b93 11.0 landed
-
Implement partition-wise grouping/aggregation.
- e2f1eb0ee30d 11.0 landed
-
Don't pass the grouping target around unnecessarily.
- 94150513ec12 11.0 landed
-
Determine grouping strategies in create_grouping_paths.
- b5996c2791f3 11.0 landed
-
Defer creation of partially-grouped relation until it's needed.
- 4f15e5d09de2 11.0 landed
-
Split create_grouping_paths into degenerate and non-degenerate cases.
- 1466bcfa4a83 11.0 landed
-
Pass additional arguments to a couple of grouping-related functions.
- 648a6c7bd815 11.0 landed
-
Fix logic error in add_paths_to_partial_grouping_rel.
- 3bfe957761ac 11.0 landed
-
Minor cleanup of code related to partially_grouped_rel.
- 5e6a63c0d102 11.0 landed
-
Add a new upper planner relation for partially-aggregated results.
- 3bf05e096b9f 11.0 landed
-
Charge cpu_tuple_cost * 0.5 for Append and MergeAppend nodes.
- 7d8ac9814bc9 11.0 landed
-
Rename enable_partition_wise_join to enable_partitionwise_join
- 2fb1abaeb016 11.0 cited
-
Factor some code out of create_grouping_paths.
- 9fd8b7d63257 11.0 landed
-
Pad XLogReaderState's main_data buffer more aggressively.
- 8735978e7aeb 11.0 cited
-
Prevent int128 from requiring more than MAXALIGN alignment.
- 7518049980be 11.0 cited
-
Fix DROP SUBSCRIPTION hang
- 8edacab20995 11.0 cited
-
Inject $(ICU_LIBS) regardless of platform.
- 66ed3829df95 11.0 cited
-
Some preliminary refactoring towards partitionwise join.
- c44c47a773bd 10.0 cited