aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2023-09-07 13:51:35 -0400
committerRobert Haas <rhaas@postgresql.org>2023-09-07 13:51:35 -0400
commit9caf042088e7416ed612e52519ee15f0717e86a7 (patch)
tree99d408a86db07a556abea89b4b222dd0f596f4a1
parentac22a9545ca906e70a819b54e76de38817c93aaf (diff)
downloadpostgresql-9caf042088e7416ed612e52519ee15f0717e86a7.tar.gz
postgresql-9caf042088e7416ed612e52519ee15f0717e86a7.zip
Reorder tests in get_cheapest_path_for_pathkeys().
Checking parallel safety should be even cheaper than cost comparison, so do that first. Also make some minor, related comment improvements. Richard Guo, reviewed by Aleksander Alekseev, Andy Fan, and me. Discussion: http://postgr.es/m/CAMbWs4-KE2wf4QPj_Sr5mX4QFtBNNKGmxK=+e=KZEGUjdG33=g@mail.gmail.com
-rw-r--r--src/backend/optimizer/path/pathkeys.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index e53ea842248..fdb60aaa8d2 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -407,7 +407,8 @@ pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
/*
* get_cheapest_path_for_pathkeys
* Find the cheapest path (according to the specified criterion) that
- * satisfies the given pathkeys and parameterization.
+ * satisfies the given pathkeys and parameterization, and is parallel-safe
+ * if required.
* Return NULL if no such path.
*
* '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,
{
Path *path = (Path *) lfirst(l);
+ /* If required, reject paths that are not parallel-safe */
+ if (require_parallel_safe && !path->parallel_safe)
+ continue;
+
/*
* Since cost comparison is a lot cheaper than pathkey comparison, do
* that first. (XXX is that still true?)
@@ -437,9 +442,6 @@ get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
compare_path_costs(matched_path, path, cost_criterion) <= 0)
continue;
- if (require_parallel_safe && !path->parallel_safe)
- continue;
-
if (pathkeys_contained_in(pathkeys, path->pathkeys) &&
bms_is_subset(PATH_REQ_OUTER(path), required_outer))
matched_path = path;