v49-0004-ignore-single-key-orderings.patch
text/x-patch
Filename: v49-0004-ignore-single-key-orderings.patch
Type: text/x-patch
Part: 3
Patch
Format: format-patch
Series: patch v49-0004
Subject: ignore single key orderings
| File | + | − |
|---|---|---|
| src/backend/optimizer/path/allpaths.c | 5 | 2 |
| src/backend/optimizer/plan/planner.c | 7 | 7 |
From c0c82add7a9cf58584683abe5d498156424beebd Mon Sep 17 00:00:00 2001
From: James Coleman <jtc331@gmail.com>
Date: Tue, 31 Mar 2020 20:32:08 -0400
Subject: [PATCH v49 4/7] ignore single key orderings
---
src/backend/optimizer/path/allpaths.c | 7 +++++--
src/backend/optimizer/plan/planner.c | 14 +++++++-------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 93d967e812..b332e474b8 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -2842,7 +2842,10 @@ generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_r
Path *subpath = (Path *) lfirst(lc2);
GatherMergePath *path;
- /* path has no ordering at all, can't use incremental sort */
+ /*
+ * If the path has no ordering at all, then we can't use either
+ * incremental sort or rely on implict sorting with a gather merge.
+ */
if (subpath->pathkeys == NIL)
continue;
@@ -2907,7 +2910,7 @@ generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_r
* Consider incremental sort, but only when the subpath is already
* partially sorted on a pathkey prefix.
*/
- if (enable_incrementalsort && presorted_keys > 0)
+ if (enable_incrementalsort && presorted_keys > 0 && list_length(useful_pathkeys) > 1)
{
Path *tmp;
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 73b7782dcb..6592d0446d 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -5010,7 +5010,7 @@ create_ordered_paths(PlannerInfo *root,
continue;
/* Likewise, if the path can't be used for incremental sort. */
- if (!presorted_keys)
+ if (!presorted_keys || list_length(root->sort_pathkeys) == 1)
continue;
/* Also consider incremental sort. */
@@ -5086,7 +5086,7 @@ create_ordered_paths(PlannerInfo *root,
* XXX This is probably duplicate with the paths we already generate
* in generate_useful_gather_paths in apply_scanjoin_target_to_paths.
*/
- if (enable_incrementalsort)
+ if (enable_incrementalsort && list_length(root->sort_pathkeys) > 1)
{
ListCell *lc;
@@ -6561,7 +6561,7 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
* when the path is not already sorted and when incremental sort
* is enabled.
*/
- if (is_sorted || !enable_incrementalsort)
+ if (is_sorted || !enable_incrementalsort || list_length(root->group_pathkeys) == 1)
continue;
/* Restore the input path (we might have added Sort on top). */
@@ -6688,7 +6688,7 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
* when the path is not already sorted and when incremental
* sort is enabled.
*/
- if (is_sorted || !enable_incrementalsort)
+ if (is_sorted || !enable_incrementalsort || list_length(root->group_pathkeys) == 1)
continue;
/* Restore the input path (we might have added Sort on top). */
@@ -7005,7 +7005,7 @@ create_partial_grouping_paths(PlannerInfo *root,
}
/* Consider incremental sort on all partial paths, if enabled. */
- if (enable_incrementalsort)
+ if (enable_incrementalsort && list_length(root->group_pathkeys) > 1)
{
foreach(lc, input_rel->pathlist)
{
@@ -7106,7 +7106,7 @@ create_partial_grouping_paths(PlannerInfo *root,
* when the path is not already sorted and when incremental sort
* is enabled.
*/
- if (is_sorted || !enable_incrementalsort)
+ if (is_sorted || !enable_incrementalsort || list_length(root->group_pathkeys) == 1)
continue;
/* Restore the input path (we might have added Sort on top). */
@@ -7278,7 +7278,7 @@ gather_grouping_paths(PlannerInfo *root, RelOptInfo *rel)
add_path(rel, path);
}
- if (!enable_incrementalsort)
+ if (!enable_incrementalsort || list_length(root->group_pathkeys) == 1)
return;
/* also consider incremental sort on partial paths, if enabled */
--
2.17.1