From 1805c68b0ae14382952c49b77ccbe30cd7605baa Mon Sep 17 00:00:00 2001 From: James Coleman Date: Wed, 1 Apr 2020 09:04:39 -0400 Subject: [PATCH v50 3/6] comment --- src/backend/optimizer/plan/planner.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index cc4718d1c9..aeb83841d7 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -4986,6 +4986,11 @@ create_ordered_paths(PlannerInfo *root, } else { + /* + * Try adding an explicit sort, but only to the cheapest total path + * since a full sort should generally add the same cost to all + * paths. + */ if (input_path == cheapest_input_path) { /* @@ -5005,7 +5010,13 @@ create_ordered_paths(PlannerInfo *root, add_path(ordered_rel, sorted_path); } - /* With incremental sort disabled, don't build those paths. */ + /* + * If incremental sort is enabled, then try it as well. Unlike with + * regular sorts, we can't just look at the cheapest path, because + * the cost of incremental sort depends on how well presorted the + * path is. Additionally incremental sort may enable a cheaper + * startup path to win out despite higher total cost. + */ if (!enable_incrementalsort) continue; -- 2.17.1