From 74fe22834253d316833185af06078b88ff5ea9ca Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Tue, 11 Apr 2023 10:49:24 +0800 Subject: [PATCH] Revise get_cheapest_parallel_safe_total_inner --- src/backend/optimizer/path/pathkeys.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 8b04d40d36d7..6bbe38aff35f 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -698,18 +698,25 @@ get_cheapest_fractional_path_for_pathkeys(List *paths, Path * get_cheapest_parallel_safe_total_inner(List *paths) { + Path *matched_path = NULL; ListCell *l; foreach(l, paths) { Path *innerpath = (Path *) lfirst(l); - if (innerpath->parallel_safe && - bms_is_empty(PATH_REQ_OUTER(innerpath))) - return innerpath; + if (!innerpath->parallel_safe || + !bms_is_empty(PATH_REQ_OUTER(innerpath))) + continue; + + if (matched_path != NULL && + compare_path_costs(matched_path, innerpath, TOTAL_COST) <= 0) + continue; + + matched_path = innerpath; } - return NULL; + return matched_path; } /****************************************************************************