@@ -62,7 +62,7 @@ int force_parallel_mode = FORCE_PARALLEL_OFF;
6262/* Hook for plugins to get control in planner() */
6363planner_hook_type planner_hook = NULL ;
6464
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 */
6666create_upper_paths_hook_type create_upper_paths_hook = NULL ;
6767
6868
@@ -1772,20 +1772,20 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
17721772 root -> upper_targets [UPPERREL_GROUP_AGG ] = grouping_target ;
17731773
17741774 /*
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.
17811784 */
17821785 if (current_rel -> fdwroutine &&
17831786 current_rel -> fdwroutine -> GetForeignUpperPaths )
17841787 current_rel -> fdwroutine -> GetForeignUpperPaths (root , current_rel );
17851788
1786- if (create_upper_paths_hook )
1787- (* create_upper_paths_hook ) (root , current_rel );
1788-
17891789 /*
17901790 * If we have grouping and/or aggregation, consider ways to implement
17911791 * that. We build a new upperrel representing the output of this
@@ -1962,6 +1962,11 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
19621962 add_path (final_rel , path );
19631963 }
19641964
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+
19651970 /* Note: currently, we leave it to callers to do set_cheapest() */
19661971}
19671972
@@ -3724,6 +3729,11 @@ create_grouping_paths(PlannerInfo *root,
37243729 errmsg ("could not implement GROUP BY" ),
37253730 errdetail ("Some of the datatypes only support hashing, while others only support sorting." )));
37263731
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+
37273737 /* Now choose the best path(s) */
37283738 set_cheapest (grouped_rel );
37293739
@@ -3780,6 +3790,11 @@ create_window_paths(PlannerInfo *root,
37803790 activeWindows );
37813791 }
37823792
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+
37833798 /* Now choose the best path(s) */
37843799 set_cheapest (window_rel );
37853800
@@ -4056,6 +4071,11 @@ create_distinct_paths(PlannerInfo *root,
40564071 errmsg ("could not implement DISTINCT" ),
40574072 errdetail ("Some of the datatypes only support hashing, while others only support sorting." )));
40584073
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+
40594079 /* Now choose the best path(s) */
40604080 set_cheapest (distinct_rel );
40614081
@@ -4117,6 +4137,11 @@ create_ordered_paths(PlannerInfo *root,
41174137 }
41184138 }
41194139
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+
41204145 /*
41214146 * No need to bother with set_cheapest here; grouping_planner does not
41224147 * need us to do it.
0 commit comments