@@ -62,7 +62,7 @@ int force_parallel_mode = FORCE_PARALLEL_OFF;
62
62
/* Hook for plugins to get control in planner() */
63
63
planner_hook_type planner_hook = NULL ;
64
64
65
- /* Hook for plugins to get control before grouping_planner plans upper rels */
65
+ /* Hook for plugins to get control when grouping_planner() plans upper rels */
66
66
create_upper_paths_hook_type create_upper_paths_hook = NULL ;
67
67
68
68
@@ -1772,20 +1772,20 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1772
1772
root -> upper_targets [UPPERREL_GROUP_AGG ] = grouping_target ;
1773
1773
1774
1774
/*
1775
- * Let extensions, particularly FDWs and CustomScan providers,
1776
- * consider injecting extension Paths into the query's upperrels,
1777
- * where they will compete with the Paths we create below. We pass
1778
- * the final scan/join rel because that's not so easily findable from
1779
- * the PlannerInfo struct; anything else the hooks want to know should
1780
- * be obtainable via "root".
1775
+ * If there is an FDW that's responsible for the final scan/join rel,
1776
+ * let it consider injecting extension Paths into the query's
1777
+ * upperrels, where they will compete with the Paths we create below.
1778
+ * We pass the final scan/join rel because that's not so easily
1779
+ * findable from the PlannerInfo struct; anything else the FDW wants
1780
+ * to know should be obtainable via "root".
1781
+ *
1782
+ * Note: CustomScan providers, as well as FDWs that don't want to
1783
+ * use this hook, can use the create_upper_paths_hook; see below.
1781
1784
*/
1782
1785
if (current_rel -> fdwroutine &&
1783
1786
current_rel -> fdwroutine -> GetForeignUpperPaths )
1784
1787
current_rel -> fdwroutine -> GetForeignUpperPaths (root , current_rel );
1785
1788
1786
- if (create_upper_paths_hook )
1787
- (* create_upper_paths_hook ) (root , current_rel );
1788
-
1789
1789
/*
1790
1790
* If we have grouping and/or aggregation, consider ways to implement
1791
1791
* that. We build a new upperrel representing the output of this
@@ -1962,6 +1962,11 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1962
1962
add_path (final_rel , path );
1963
1963
}
1964
1964
1965
+ /* Let extensions possibly add some more paths */
1966
+ if (create_upper_paths_hook )
1967
+ (* create_upper_paths_hook ) (root , UPPERREL_FINAL ,
1968
+ current_rel , final_rel );
1969
+
1965
1970
/* Note: currently, we leave it to callers to do set_cheapest() */
1966
1971
}
1967
1972
@@ -3724,6 +3729,11 @@ create_grouping_paths(PlannerInfo *root,
3724
3729
errmsg ("could not implement GROUP BY" ),
3725
3730
errdetail ("Some of the datatypes only support hashing, while others only support sorting." )));
3726
3731
3732
+ /* Let extensions possibly add some more paths */
3733
+ if (create_upper_paths_hook )
3734
+ (* create_upper_paths_hook ) (root , UPPERREL_GROUP_AGG ,
3735
+ input_rel , grouped_rel );
3736
+
3727
3737
/* Now choose the best path(s) */
3728
3738
set_cheapest (grouped_rel );
3729
3739
@@ -3780,6 +3790,11 @@ create_window_paths(PlannerInfo *root,
3780
3790
activeWindows );
3781
3791
}
3782
3792
3793
+ /* Let extensions possibly add some more paths */
3794
+ if (create_upper_paths_hook )
3795
+ (* create_upper_paths_hook ) (root , UPPERREL_WINDOW ,
3796
+ input_rel , window_rel );
3797
+
3783
3798
/* Now choose the best path(s) */
3784
3799
set_cheapest (window_rel );
3785
3800
@@ -4056,6 +4071,11 @@ create_distinct_paths(PlannerInfo *root,
4056
4071
errmsg ("could not implement DISTINCT" ),
4057
4072
errdetail ("Some of the datatypes only support hashing, while others only support sorting." )));
4058
4073
4074
+ /* Let extensions possibly add some more paths */
4075
+ if (create_upper_paths_hook )
4076
+ (* create_upper_paths_hook ) (root , UPPERREL_DISTINCT ,
4077
+ input_rel , distinct_rel );
4078
+
4059
4079
/* Now choose the best path(s) */
4060
4080
set_cheapest (distinct_rel );
4061
4081
@@ -4117,6 +4137,11 @@ create_ordered_paths(PlannerInfo *root,
4117
4137
}
4118
4138
}
4119
4139
4140
+ /* Let extensions possibly add some more paths */
4141
+ if (create_upper_paths_hook )
4142
+ (* create_upper_paths_hook ) (root , UPPERREL_ORDERED ,
4143
+ input_rel , ordered_rel );
4144
+
4120
4145
/*
4121
4146
* No need to bother with set_cheapest here; grouping_planner does not
4122
4147
* need us to do it.
0 commit comments