src/backend/optimizer/path/allpaths.c | 22 +++++++++++++++++----- src/include/optimizer/paths.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index d9a2f9b..100274e 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -62,6 +62,7 @@ int min_parallel_index_scan_size; /* Hook for plugins to get control in set_rel_pathlist() */ set_rel_pathlist_hook_type set_rel_pathlist_hook = NULL; +set_rel_pathlist_hook_type post_rel_pathlist_hook = NULL; /* Hook for plugins to replace standard_join_search() */ join_search_hook_type join_search_hook = NULL; @@ -479,6 +480,14 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, } /* + * Allow a plugin to editorialize on the set of Paths for this base + * relation. It could add new regular paths (such as CustomPaths) by + * calling add_path(), partial paths by add_partial_path(). + */ + if (set_rel_pathlist_hook) + (*set_rel_pathlist_hook) (root, rel, rti, rte); + + /* * If this is a baserel, consider gathering any partial paths we may have * created for it. (If we tried to gather inheritance children, we could * end up with a very large number of gather nodes, each trying to grab @@ -489,12 +498,15 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, generate_gather_paths(root, rel); /* - * Allow a plugin to editorialize on the set of Paths for this base - * relation. It could add new paths (such as CustomPaths) by calling - * add_path(), or delete or modify paths added by the core code. + * Allow a plugin to manipulate all the set of Paths for this base + * relation. It could delete or modify paths added by the core or + * extensions at the prior hook. + * Note that we don't recommend to add partial paths here, because + * GatherPath is already built above, and alternative cheaper partial + * path may release path-node in use. */ - if (set_rel_pathlist_hook) - (*set_rel_pathlist_hook) (root, rel, rti, rte); + if (post_rel_pathlist_hook) + (*post_rel_pathlist_hook) (root, rel, rti, rte); /* Now find the cheapest of the paths for this rel */ set_cheapest(rel); diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h index 1d3fb5c..1950775 100644 --- a/src/include/optimizer/paths.h +++ b/src/include/optimizer/paths.h @@ -31,6 +31,7 @@ typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root, Index rti, RangeTblEntry *rte); extern PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook; +extern PGDLLIMPORT set_rel_pathlist_hook_type post_rel_pathlist_hook; /* Hook for plugins to get control in add_paths_to_joinrel() */ typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root,