 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 5f74d3b..757249b 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -64,6 +64,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;
@@ -480,6 +481,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, we should normally consider gathering any partial
 	 * paths we may have created for it.
 	 *
@@ -497,12 +506,15 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
 		generate_gather_paths(root, rel, false);
 
 	/*
-	 * 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 cafde30..74bd9c3 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,
