diff options
Diffstat (limited to 'src/backend/optimizer/util/pathnode.c')
-rw-r--r-- | src/backend/optimizer/util/pathnode.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index d1c4e1a6aa7..b8b1eae295e 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -1889,6 +1889,16 @@ create_gather_merge_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, Assert(subpath->parallel_safe); Assert(pathkeys); + /* + * The subpath should guarantee that it is adequately ordered either by + * adding an explicit sort node or by using presorted input. We cannot + * add an explicit Sort node for the subpath in createplan.c on additional + * pathkeys, because we can't guarantee the sort would be safe. For + * example, expressions may be volatile or otherwise parallel unsafe. + */ + if (!pathkeys_contained_in(pathkeys, subpath->pathkeys)) + elog(ERROR, "gather merge input not sufficiently sorted"); + pathnode->path.pathtype = T_GatherMerge; pathnode->path.parent = rel; pathnode->path.param_info = get_baserel_parampathinfo(root, rel, @@ -1900,29 +1910,8 @@ create_gather_merge_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, pathnode->path.pathkeys = pathkeys; pathnode->path.pathtarget = target ? target : rel->reltarget; - if (pathkeys_contained_in(pathkeys, subpath->pathkeys)) - { - /* Subpath is adequately ordered, we won't need to sort it */ - input_startup_cost += subpath->startup_cost; - input_total_cost += subpath->total_cost; - } - else - { - /* We'll need to insert a Sort node, so include cost for that */ - Path sort_path; /* dummy for result of cost_sort */ - - cost_sort(&sort_path, - root, - pathkeys, - subpath->total_cost, - subpath->rows, - subpath->pathtarget->width, - 0.0, - work_mem, - -1); - input_startup_cost += sort_path.startup_cost; - input_total_cost += sort_path.total_cost; - } + input_startup_cost += subpath->startup_cost; + input_total_cost += subpath->total_cost; cost_gather_merge(pathnode, root, rel, pathnode->path.param_info, input_startup_cost, input_total_cost, rows); |