Skip to content

Commit 8ddad92

Browse files
author
hackorum
committed
Apply cost_append_scale_subpath_cost.diff
1 parent b597835 commit 8ddad92

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/backend/optimizer/path/costsize.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,19 +2461,29 @@ cost_append(AppendPath *apath, PlannerInfo *root)
24612461
* Apply parallel divisor to subpaths. Scale the number of rows
24622462
* for each partial subpath based on the ratio of the parallel
24632463
* divisor originally used for the subpath to the one we adopted.
2464-
* Also add the cost of partial paths to the total cost, but
2465-
* ignore non-partial paths for now.
2464+
* Also add the scaled cost of partial paths to the total cost,
2465+
* but ignore non-partial paths for now.
24662466
*/
24672467
if (i < apath->first_partial_path)
24682468
apath->path.rows += subpath->rows / parallel_divisor;
24692469
else
24702470
{
24712471
double subpath_parallel_divisor;
2472+
double scale_factor;
2473+
Cost run_cost;
24722474

24732475
subpath_parallel_divisor = get_parallel_divisor(subpath);
2474-
apath->path.rows += subpath->rows * (subpath_parallel_divisor /
2475-
parallel_divisor);
2476-
apath->path.total_cost += subpath->total_cost;
2476+
scale_factor = subpath_parallel_divisor / parallel_divisor;
2477+
apath->path.rows += subpath->rows * scale_factor;
2478+
/*
2479+
* XXX run_cost includes both CPU cost, which is divided among
2480+
* workers, and disk cost, which is not. Unfortunately we
2481+
* don't have enough information to separate the two, so scale
2482+
* the whole run_cost.
2483+
*/
2484+
run_cost = subpath->total_cost - subpath->startup_cost;
2485+
apath->path.total_cost += subpath->startup_cost +
2486+
run_cost * scale_factor;;
24772487
}
24782488

24792489
apath->path.disabled_nodes += subpath->disabled_nodes;

0 commit comments

Comments
 (0)