Commit 8c314b98 authored by Tom Lane's avatar Tom Lane

Finish refactoring make_foo() functions in createplan.c.

This patch removes some redundant cost calculations that I left for later
cleanup in commit 3fc6e2d7.  There's now a uniform policy that the
make_foo() convenience functions don't do any cost calculations.  Most of
their callers copy costs from the source Path node, and for those that
don't, the calculation in the make_foo() function wasn't necessarily right
anyhow.  (make_result() was particularly a mess, as it was serving multiple
callers using cost calcs designed for only the first one or two that had
ever existed.)  Aside from saving a few cycles, this ensures that what
EXPLAIN prints matches the costs we used for planning purposes.  It does
not change any planner decisions, since the decisions are already made.
parent 7400559a
This diff is collapsed.
......@@ -82,7 +82,7 @@ query_planner(PlannerInfo *root, List *tlist,
/* The only path for it is a trivial Result path */
add_path(final_rel, (Path *)
create_result_path(final_rel,
create_result_path(root, final_rel,
&(final_rel->reltarget),
(List *) parse->jointree->quals));
......
......@@ -3143,7 +3143,7 @@ create_grouping_paths(PlannerInfo *root,
while (--nrows >= 0)
{
path = (Path *)
create_result_path(grouped_rel,
create_result_path(root, grouped_rel,
target,
(List *) parse->havingQual);
paths = lappend(paths, path);
......@@ -3159,7 +3159,7 @@ create_grouping_paths(PlannerInfo *root,
{
/* No grouping sets, or just one, so one output row */
path = (Path *)
create_result_path(grouped_rel,
create_result_path(root, grouped_rel,
target,
(List *) parse->havingQual);
}
......
......@@ -1328,7 +1328,8 @@ create_merge_append_path(PlannerInfo *root,
* jointree.
*/
ResultPath *
create_result_path(RelOptInfo *rel, PathTarget *target, List *quals)
create_result_path(PlannerInfo *root, RelOptInfo *rel,
PathTarget *target, List *resconstantqual)
{
ResultPath *pathnode = makeNode(ResultPath);
......@@ -1340,23 +1341,22 @@ create_result_path(RelOptInfo *rel, PathTarget *target, List *quals)
pathnode->path.parallel_safe = rel->consider_parallel;
pathnode->path.parallel_degree = 0;
pathnode->path.pathkeys = NIL;
pathnode->quals = quals;
pathnode->quals = resconstantqual;
/* Hardly worth defining a cost_result() function ... just do it */
pathnode->path.rows = 1;
pathnode->path.startup_cost = target->cost.startup;
pathnode->path.total_cost = target->cost.startup +
cpu_tuple_cost + target->cost.per_tuple;
if (resconstantqual)
{
QualCost qual_cost;
/*
* In theory we should include the qual eval cost as well, but at present
* that doesn't accomplish much except duplicate work that will be done
* again in make_result; since this is only used for degenerate cases,
* nothing interesting will be done with the path cost values.
*
* XXX should refactor so that make_result does not do costing work, at
* which point this will need to do it honestly.
*/
cost_qual_eval(&qual_cost, resconstantqual, root);
/* resconstantqual is evaluated once at startup */
pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
}
return pathnode;
}
......@@ -2162,7 +2162,7 @@ create_projection_path(PlannerInfo *root,
/*
* The Result node's cost is cpu_tuple_cost per row, plus the cost of
* evaluating the tlist.
* evaluating the tlist. There is no qual to worry about.
*/
pathnode->path.rows = subpath->rows;
pathnode->path.startup_cost = subpath->startup_cost + target->cost.startup;
......
......@@ -68,8 +68,8 @@ extern MergeAppendPath *create_merge_append_path(PlannerInfo *root,
List *subpaths,
List *pathkeys,
Relids required_outer);
extern ResultPath *create_result_path(RelOptInfo *rel,
PathTarget *target, List *quals);
extern ResultPath *create_result_path(PlannerInfo *root, RelOptInfo *rel,
PathTarget *target, List *resconstantqual);
extern MaterialPath *create_material_path(RelOptInfo *rel, Path *subpath);
extern UniquePath *create_unique_path(PlannerInfo *root, RelOptInfo *rel,
Path *subpath, SpecialJoinInfo *sjinfo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment