Re: Partition-wise aggregation/grouping
Jeevan Chalke <jeevan.chalke@enterprisedb.com>
Attachments
- partition-wise-agg-v2.tar.gz (application/x-gzip)
On Wed, Aug 23, 2017 at 4:43 PM, Jeevan Chalke < jeevan.chalke@enterprisedb.com> wrote: > Hi, > > Attached is the patch to implement partition-wise aggregation/grouping. > > As explained earlier, we produce a full aggregation for each partition when > partition keys are leading group by clauses and then append is performed. > Else we do a partial aggregation on each partition, append them and then > add > finalization step over it. > > I have observed that cost estimated for partition-wise aggregation and cost > for the plans without partition-wise aggregation is almost same. However, > execution time shows significant improvement (as explained my in the very > first email) with partition-wise aggregates. Planner chooses a plan > according > to the costs, and thus most of the time plan without partition-wise > aggregation is chosen. Hence, to force partition-wise plans and for the > regression runs, I have added a GUC named partition_wise_agg_cost_factor to > adjust the costings. > > This feature is only used when enable_partition_wise_agg GUC is set to on. > > Here are the details of the patches in the patch-set: > Here are the new patch-set re-based on HEAD (f0a0c17) and latest partition-wise join (v29) patches. > > 0001 - Refactors sort and hash final grouping paths into separate > functions. > Since partition-wise aggregation too builds paths same as that of > create_grouping_paths(), separated path creation for sort and hash agg into > separate functions. These functions later used by main partition-wise > aggregation/grouping patch. > > 0002 - Passes targetlist to get_number_of_groups(). > We need to estimate groups for individual child relations and thus need to > pass targetlist corresponding to the child rel. > > 0003 - Adds enable_partition_wise_agg and partition_wise_agg_cost_factor > GUCs. > > 0004 - Implements partition-wise aggregation. > > 0005 - Adds test-cases. > > 0006 - postgres_fdw changes which enable pushing aggregation for other > upper > relations. > 0007 - Provides infrastructure to allow partial aggregation This will allow us to push the partial aggregation over fdw. With this one can write SUM(PARTIAL x) to get a partial sum result. Since PARTIAL is used in syntax, I need to move that to a reserved keywords category. This is kind of PoC patch and needs input over approach and the way it is implemented. 0008 - Teaches postgres_fdw to push partial aggregation With this we can push aggregate on remote server when GROUP BY key does not match with the PARTITION key too. > > > Since this patch is highly dependent on partition-wise join [1], one needs > to > apply all those patches on HEAD (my repository head was at: > 66ed3829df959adb47f71d7c903ac59f0670f3e1) before applying these patches in > order. > > Suggestions / feedback / inputs ? > > [1] https://www.postgresql.org/message-id/CAFjFpRd9Vqh_=-Ldv- > XqWY006d07TJ+VXuhXCbdj=P1jukYBrw@mail.gmail.com > > > -- Jeevan Chalke Principal Software Engineer, 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