From bec4ad16097c6d0d80509600d7e45940a8f98251 Mon Sep 17 00:00:00 2001 From: Zhang Mingli Date: Fri, 11 Aug 2023 18:33:13 +0800 Subject: [PATCH] Add final Motion earlier in grouping_planner for partial paths This is same as pathlist, if we know where the result will be needed, create a Motion to move it there. standard_planner() will tack a Motion on top of the cheapest partial path anyway, if we don't do it here. But doing the Motion here allows the cost of the Motion to be taken into account when deciding which partial path is the cheapest. Authored-by: Zhang Mingli avamingli@gmail.com --- src/backend/optimizer/plan/planner.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 41355826c62..59e436b2ed4 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -2579,6 +2579,26 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) offset_est, count_est); } + /* + * Like pathlist: + * Take Motion cost into accout before standard_planner(). + * Don't foo by one-phase LIMIT with partial_path here. + */ + if ((CdbPathLocus_IsHashed(root->final_locus) || + CdbPathLocus_IsSingleQE(root->final_locus) || + CdbPathLocus_IsEntry(root->final_locus) || + CdbPathLocus_IsReplicated(root->final_locus)) && + !root->glob->is_parallel_cursor) + { + Path *orig_path = partial_path; + + partial_path = cdbpath_create_motion_path(root, orig_path, + root->sort_pathkeys, + false, + root->final_locus); + if (!partial_path) + partial_path = orig_path; + } add_partial_path(final_rel, partial_path); } }