double spc_seq_page_cost;
QualCost qpqual_cost;
Cost cpu_per_tuple;
+ double parallel_divisor = 1;
/* Should only be applied to base relations */
Assert(baserel->relid > 0);
Assert(baserel->rtekind == RTE_RELATION);
- /* Mark the path with the correct row estimate */
- if (param_info)
- path->rows = param_info->ppi_rows;
- else
- path->rows = baserel->rows;
-
/*
* Primitive parallel cost model. Assume the leader will do half as much
* work as a regular worker, because it will also need to read the tuples
* this will probably need to be changed at some point...
*/
if (path->parallel_degree > 0)
- path->rows = path->rows / (path->parallel_degree + 0.5);
+ parallel_divisor = path->parallel_degree + 0.5;
+
+ /* Mark the path with the correct row estimate */
+ if (param_info)
+ path->rows = param_info->ppi_rows / parallel_divisor;
+ else
+ path->rows = baserel->rows / parallel_divisor;
if (!enable_seqscan)
startup_cost += disable_cost;
/*
* disk costs
*/
- run_cost += spc_seq_page_cost * baserel->pages;
+ run_cost += spc_seq_page_cost * baserel->pages / parallel_divisor;
/* CPU costs */
get_restriction_qual_cost(root, baserel, param_info, &qpqual_cost);
startup_cost += qpqual_cost.startup;
cpu_per_tuple = cpu_tuple_cost + qpqual_cost.per_tuple;
- run_cost += cpu_per_tuple * baserel->tuples;
+ run_cost += cpu_per_tuple * baserel->tuples / parallel_divisor;
path->startup_cost = startup_cost;
path->total_cost = startup_cost + run_cost;