diff options
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index fd9a7da6ff..1e76c0345b 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -193,17 +193,12 @@ cost_seqscan(Path *path, PlannerInfo *root, 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 @@ -212,7 +207,13 @@ cost_seqscan(Path *path, PlannerInfo *root, * 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; @@ -225,14 +226,14 @@ cost_seqscan(Path *path, PlannerInfo *root, /* * 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; |