4949 * Portions Copyright (c) 1994, Regents of the University of California
5050 *
5151 * IDENTIFICATION
52- * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.146 2005/06/05 22:32:55 tgl Exp $
52+ * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.147 2005/08/27 22:37:00 tgl Exp $
5353 *
5454 *-------------------------------------------------------------------------
5555 */
@@ -872,7 +872,7 @@ cost_agg(Path *path, PlannerInfo *root,
872872 * for grouping comparisons.
873873 *
874874 * We will produce a single output tuple if not grouping, and a tuple per
875- * group otherwise.
875+ * group otherwise. We charge cpu_tuple_cost for each output tuple.
876876 *
877877 * Note: in this cost model, AGG_SORTED and AGG_HASHED have exactly the
878878 * same total CPU cost, but AGG_SORTED has lower startup cost.If the
@@ -888,7 +888,7 @@ cost_agg(Path *path, PlannerInfo *root,
888888startup_cost = input_total_cost ;
889889startup_cost += cpu_operator_cost * (input_tuples + 1 )* numAggs ;
890890/* we aren't grouping */
891- total_cost = startup_cost ;
891+ total_cost = startup_cost + cpu_tuple_cost ;
892892}
893893else if (aggstrategy == AGG_SORTED )
894894{
@@ -899,6 +899,7 @@ cost_agg(Path *path, PlannerInfo *root,
899899total_cost += cpu_operator_cost * input_tuples * numGroupCols ;
900900total_cost += cpu_operator_cost * input_tuples * numAggs ;
901901total_cost += cpu_operator_cost * numGroups * numAggs ;
902+ total_cost += cpu_tuple_cost * numGroups ;
902903}
903904else
904905{
@@ -908,6 +909,7 @@ cost_agg(Path *path, PlannerInfo *root,
908909startup_cost += cpu_operator_cost * input_tuples * numAggs ;
909910total_cost = startup_cost ;
910911total_cost += cpu_operator_cost * numGroups * numAggs ;
912+ total_cost += cpu_tuple_cost * numGroups ;
911913}
912914
913915path -> startup_cost = startup_cost ;