mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
postgres_fdw: Push down partition-wise aggregation.
Since commit7012b132d0
, postgres_fdw has been able to push down the toplevel aggregation operation to the remote server. Commite2f1eb0ee3
made it possible to break down the toplevel aggregation into one aggregate per partition. This commit lets postgres_fdw push down aggregation in that case just as it does at the top level. In order to make this work, this commit adds an additional argument to the GetForeignUpperPaths FDW API. A matching argument is added to the signature for create_upper_paths_hook. Third-party code using either of these will need to be updated. Also adjust create_foreignscan_plan() so that it picks up the correct set of relids in this case. Jeevan Chalke, reviewed by Ashutosh Bapat and by me and with some adjustments by me. The larger patch series of which this patch is a part was also reviewed and tested by Antonin Houska, Rajkumar Raghuwanshi, David Rowley, Dilip Kumar, Konstantin Knizhnik, Pascal Legrand, and Rafia Sabih. Discussion: http://postgr.es/m/CAM2+6=V64_xhstVHie0Rz=KPEQnLJMZt_e314P0jaT_oJ9MR8A@mail.gmail.com Discussion: http://postgr.es/m/CAM2+6=XPWujjmj5zUaBTGDoB38CemwcPmjkRy0qOcsQj_V+2sQ@mail.gmail.com
This commit is contained in:
@ -3572,7 +3572,7 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
|
||||
* upper rel doesn't have relids set, but it covers all the base relations
|
||||
* participating in the underlying scan, so use root's all_baserels.
|
||||
*/
|
||||
if (IS_UPPER_REL(rel))
|
||||
if (rel->reloptkind == RELOPT_UPPER_REL)
|
||||
scan_plan->fs_relids = root->all_baserels;
|
||||
else
|
||||
scan_plan->fs_relids = best_path->path.parent->relids;
|
||||
|
@ -2206,12 +2206,13 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
|
||||
if (final_rel->fdwroutine &&
|
||||
final_rel->fdwroutine->GetForeignUpperPaths)
|
||||
final_rel->fdwroutine->GetForeignUpperPaths(root, UPPERREL_FINAL,
|
||||
current_rel, final_rel);
|
||||
current_rel, final_rel,
|
||||
NULL);
|
||||
|
||||
/* Let extensions possibly add some more paths */
|
||||
if (create_upper_paths_hook)
|
||||
(*create_upper_paths_hook) (root, UPPERREL_FINAL,
|
||||
current_rel, final_rel);
|
||||
current_rel, final_rel, NULL);
|
||||
|
||||
/* Note: currently, we leave it to callers to do set_cheapest() */
|
||||
}
|
||||
@ -4024,12 +4025,14 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
|
||||
if (grouped_rel->fdwroutine &&
|
||||
grouped_rel->fdwroutine->GetForeignUpperPaths)
|
||||
grouped_rel->fdwroutine->GetForeignUpperPaths(root, UPPERREL_GROUP_AGG,
|
||||
input_rel, grouped_rel);
|
||||
input_rel, grouped_rel,
|
||||
extra);
|
||||
|
||||
/* Let extensions possibly add some more paths */
|
||||
if (create_upper_paths_hook)
|
||||
(*create_upper_paths_hook) (root, UPPERREL_GROUP_AGG,
|
||||
input_rel, grouped_rel);
|
||||
input_rel, grouped_rel,
|
||||
extra);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -4461,12 +4464,13 @@ create_window_paths(PlannerInfo *root,
|
||||
if (window_rel->fdwroutine &&
|
||||
window_rel->fdwroutine->GetForeignUpperPaths)
|
||||
window_rel->fdwroutine->GetForeignUpperPaths(root, UPPERREL_WINDOW,
|
||||
input_rel, window_rel);
|
||||
input_rel, window_rel,
|
||||
NULL);
|
||||
|
||||
/* Let extensions possibly add some more paths */
|
||||
if (create_upper_paths_hook)
|
||||
(*create_upper_paths_hook) (root, UPPERREL_WINDOW,
|
||||
input_rel, window_rel);
|
||||
input_rel, window_rel, NULL);
|
||||
|
||||
/* Now choose the best path(s) */
|
||||
set_cheapest(window_rel);
|
||||
@ -4765,12 +4769,13 @@ create_distinct_paths(PlannerInfo *root,
|
||||
if (distinct_rel->fdwroutine &&
|
||||
distinct_rel->fdwroutine->GetForeignUpperPaths)
|
||||
distinct_rel->fdwroutine->GetForeignUpperPaths(root, UPPERREL_DISTINCT,
|
||||
input_rel, distinct_rel);
|
||||
input_rel, distinct_rel,
|
||||
NULL);
|
||||
|
||||
/* Let extensions possibly add some more paths */
|
||||
if (create_upper_paths_hook)
|
||||
(*create_upper_paths_hook) (root, UPPERREL_DISTINCT,
|
||||
input_rel, distinct_rel);
|
||||
input_rel, distinct_rel, NULL);
|
||||
|
||||
/* Now choose the best path(s) */
|
||||
set_cheapest(distinct_rel);
|
||||
@ -4908,12 +4913,13 @@ create_ordered_paths(PlannerInfo *root,
|
||||
if (ordered_rel->fdwroutine &&
|
||||
ordered_rel->fdwroutine->GetForeignUpperPaths)
|
||||
ordered_rel->fdwroutine->GetForeignUpperPaths(root, UPPERREL_ORDERED,
|
||||
input_rel, ordered_rel);
|
||||
input_rel, ordered_rel,
|
||||
NULL);
|
||||
|
||||
/* Let extensions possibly add some more paths */
|
||||
if (create_upper_paths_hook)
|
||||
(*create_upper_paths_hook) (root, UPPERREL_ORDERED,
|
||||
input_rel, ordered_rel);
|
||||
input_rel, ordered_rel, NULL);
|
||||
|
||||
/*
|
||||
* No need to bother with set_cheapest here; grouping_planner does not
|
||||
@ -6694,7 +6700,8 @@ create_partial_grouping_paths(PlannerInfo *root,
|
||||
|
||||
fdwroutine->GetForeignUpperPaths(root,
|
||||
UPPERREL_PARTIAL_GROUP_AGG,
|
||||
input_rel, partially_grouped_rel);
|
||||
input_rel, partially_grouped_rel,
|
||||
extra);
|
||||
}
|
||||
|
||||
return partially_grouped_rel;
|
||||
|
@ -1032,7 +1032,7 @@ postprocess_setop_rel(PlannerInfo *root, RelOptInfo *rel)
|
||||
*/
|
||||
if (create_upper_paths_hook)
|
||||
(*create_upper_paths_hook) (root, UPPERREL_SETOP,
|
||||
NULL, rel);
|
||||
NULL, rel, NULL);
|
||||
|
||||
/* Select cheapest path */
|
||||
set_cheapest(rel);
|
||||
|
Reference in New Issue
Block a user