&gm_plan->collations,
&gm_plan->nullsFirst);
-
/*
* All gather merge paths should have already guaranteed the necessary
- * sort order either by adding an explicit sort node or by using presorted
- * input. We can't simply add a sort here on additional pathkeys, because
- * we can't guarantee the sort would be safe. For example, expressions may
- * be volatile or otherwise parallel unsafe.
+ * sort order. See create_gather_merge_path.
*/
- if (!pathkeys_contained_in(pathkeys, best_path->subpath->pathkeys))
- elog(ERROR, "gather merge input not sufficiently sorted");
+ Assert(pathkeys_contained_in(pathkeys, best_path->subpath->pathkeys));
/* Now insert the subplan under GatherMerge. */
gm_plan->plan.lefttree = subplan;
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,
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);