@@ -407,7 +407,8 @@ pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
407407/*
408408 * get_cheapest_path_for_pathkeys
409409 * Find the cheapest path (according to the specified criterion) that
410- * satisfies the given pathkeys and parameterization.
410+ * satisfies the given pathkeys and parameterization, and is parallel-safe
411+ * if required.
411412 * Return NULL if no such path.
412413 *
413414 * 'paths' is a list of possible paths that all generate the same relation
@@ -429,6 +430,10 @@ get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
429430 {
430431 Path * path = (Path * ) lfirst (l );
431432
433+ /* If required, reject paths that are not parallel-safe */
434+ if (require_parallel_safe && !path -> parallel_safe )
435+ continue ;
436+
432437 /*
433438 * Since cost comparison is a lot cheaper than pathkey comparison, do
434439 * that first. (XXX is that still true?)
@@ -437,9 +442,6 @@ get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
437442 compare_path_costs (matched_path , path , cost_criterion ) <= 0 )
438443 continue ;
439444
440- if (require_parallel_safe && !path -> parallel_safe )
441- continue ;
442-
443445 if (pathkeys_contained_in (pathkeys , path -> pathkeys ) &&
444446 bms_is_subset (PATH_REQ_OUTER (path ), required_outer ))
445447 matched_path = path ;
0 commit comments