From 5a5287d8eb2b67f6b49dc657f7d3cc58fd46e061 Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Tue, 11 Apr 2023 10:49:24 +0800 Subject: [PATCH v1] 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 e53ea84224..51c810d089 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -497,18 +497,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; } /**************************************************************************** -- 2.31.0