Costing fixes. gather_pushdown
authorRobert Haas <[email protected]>
Wed, 2 Dec 2015 19:43:12 +0000 (19:43 +0000)
committerRobert Haas <[email protected]>
Wed, 2 Dec 2015 19:43:12 +0000 (19:43 +0000)
src/backend/optimizer/path/costsize.c

index fd9a7da6ff021e1d682c6eb8b5ac6f35a31dc3cd..1e76c0345b8867dc87daaead11673e852bc35da5 100644 (file)
@@ -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;