Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f1f01de

Browse files
committed
Redefine create_upper_paths_hook as being invoked once per upper relation.
Per discussion, this gives potential users of the hook more flexibility, because they can build custom Paths that implement only one stage of upper processing atop core-provided Paths for earlier stages.
1 parent 7a5f8b5 commit f1f01de

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/backend/optimizer/plan/planner.c

+35-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int force_parallel_mode = FORCE_PARALLEL_OFF;
6262
/* Hook for plugins to get control in planner() */
6363
planner_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 */
6666
create_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.

src/backend/optimizer/prep/prepunion.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ plan_set_operations(PlannerInfo *root)
206206
/* Add only the final path to the SETOP upperrel. */
207207
add_path(setop_rel, path);
208208

209-
/* Select cheapest path (pretty easy at the moment) */
209+
/* Let extensions possibly add some more paths */
210+
if (create_upper_paths_hook)
211+
(*create_upper_paths_hook) (root, UPPERREL_SETOP,
212+
NULL, setop_rel);
213+
214+
/* Select cheapest path */
210215
set_cheapest(setop_rel);
211216

212217
return setop_rel;

src/include/optimizer/planner.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ typedef PlannedStmt *(*planner_hook_type) (Query *parse,
2424
ParamListInfo boundParams);
2525
extern PGDLLIMPORT planner_hook_type planner_hook;
2626

27-
/* Hook for plugins to get control before grouping_planner plans upper rels */
27+
/* Hook for plugins to get control when grouping_planner() plans upper rels */
2828
typedef void (*create_upper_paths_hook_type) (PlannerInfo *root,
29-
RelOptInfo *scan_join_rel);
29+
UpperRelationKind stage,
30+
RelOptInfo *input_rel,
31+
RelOptInfo *output_rel);
3032
extern PGDLLIMPORT create_upper_paths_hook_type create_upper_paths_hook;
3133

3234

0 commit comments

Comments
 (0)