cost_agg really ought to charge something per output tuple; else there
authorTom Lane <[email protected]>
Sat, 27 Aug 2005 22:37:00 +0000 (22:37 +0000)
committerTom Lane <[email protected]>
Sat, 27 Aug 2005 22:37:00 +0000 (22:37 +0000)
are cases where it appears to have zero run cost.

src/backend/optimizer/path/costsize.c

index 55a5b1321e509d510249ec5570b4b16ba56efbcf..75b6928209971dc43d5c4ed87675962fdc93b71e 100644 (file)
@@ -872,7 +872,7 @@ cost_agg(Path *path, PlannerInfo *root,
         * for grouping comparisons.
         *
         * We will produce a single output tuple if not grouping, and a tuple per
-        * group otherwise.
+        * group otherwise.  We charge cpu_tuple_cost for each output tuple.
         *
         * Note: in this cost model, AGG_SORTED and AGG_HASHED have exactly the
         * same total CPU cost, but AGG_SORTED has lower startup cost.  If the
@@ -888,7 +888,7 @@ cost_agg(Path *path, PlannerInfo *root,
                startup_cost = input_total_cost;
                startup_cost += cpu_operator_cost * (input_tuples + 1) * numAggs;
                /* we aren't grouping */
-               total_cost = startup_cost;
+               total_cost = startup_cost + cpu_tuple_cost;
        }
        else if (aggstrategy == AGG_SORTED)
        {
@@ -899,6 +899,7 @@ cost_agg(Path *path, PlannerInfo *root,
                total_cost += cpu_operator_cost * input_tuples * numGroupCols;
                total_cost += cpu_operator_cost * input_tuples * numAggs;
                total_cost += cpu_operator_cost * numGroups * numAggs;
+               total_cost += cpu_tuple_cost * numGroups;
        }
        else
        {
@@ -908,6 +909,7 @@ cost_agg(Path *path, PlannerInfo *root,
                startup_cost += cpu_operator_cost * input_tuples * numAggs;
                total_cost = startup_cost;
                total_cost += cpu_operator_cost * numGroups * numAggs;
+               total_cost += cpu_tuple_cost * numGroups;
        }
 
        path->startup_cost = startup_cost;