1010 *
1111 *
1212 * IDENTIFICATION
13- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.122 2002/11/15 02:36:53 tgl Exp $
13+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.123 2002/11/19 23:21:58 tgl Exp $
1414 *
1515 *-------------------------------------------------------------------------
1616 */
@@ -1684,30 +1684,28 @@ make_material(List *tlist, Plan *lefttree)
16841684
16851685Agg *
16861686make_agg (List * tlist , List * qual , AggStrategy aggstrategy ,
1687- int ngrp , AttrNumber * grpColIdx , Plan * lefttree )
1687+ int ngrp , AttrNumber * grpColIdx , long numGroups , int numAggs ,
1688+ Plan * lefttree )
16881689{
16891690 Agg * node = makeNode (Agg );
16901691 Plan * plan = & node -> plan ;
16911692
16921693 node -> aggstrategy = aggstrategy ;
16931694 node -> numCols = ngrp ;
16941695 node -> grpColIdx = grpColIdx ;
1696+ node -> numGroups = numGroups ;
16951697
16961698 copy_plan_costsize (plan , lefttree );
16971699
16981700 /*
16991701 * Charge one cpu_operator_cost per aggregate function per input
17001702 * tuple.
17011703 */
1702- plan -> total_cost += cpu_operator_cost * plan -> plan_rows *
1703- (length (pull_agg_clause ((Node * ) tlist )) +
1704- length (pull_agg_clause ((Node * ) qual )));
1704+ plan -> total_cost += cpu_operator_cost * plan -> plan_rows * numAggs ;
17051705
17061706 /*
17071707 * We will produce a single output tuple if not grouping,
1708- * and a tuple per group otherwise. For now, estimate the number of
1709- * groups as 10% of the number of tuples --- bogus, but how to do
1710- * better?
1708+ * and a tuple per group otherwise.
17111709 */
17121710 if (aggstrategy == AGG_PLAIN )
17131711 {
@@ -1716,10 +1714,7 @@ make_agg(List *tlist, List *qual, AggStrategy aggstrategy,
17161714 }
17171715 else
17181716 {
1719- plan -> plan_rows *= 0.1 ;
1720- if (plan -> plan_rows < 1 )
1721- plan -> plan_rows = 1 ;
1722- node -> numGroups = (long ) plan -> plan_rows ;
1717+ plan -> plan_rows = numGroups ;
17231718 }
17241719
17251720 plan -> state = (EState * ) NULL ;
@@ -1735,6 +1730,7 @@ Group *
17351730make_group (List * tlist ,
17361731 int ngrp ,
17371732 AttrNumber * grpColIdx ,
1733+ double numGroups ,
17381734 Plan * lefttree )
17391735{
17401736 Group * node = makeNode (Group );
@@ -1748,13 +1744,8 @@ make_group(List *tlist,
17481744 */
17491745 plan -> total_cost += cpu_operator_cost * plan -> plan_rows * ngrp ;
17501746
1751- /*
1752- * Estimate the number of groups as 10% of the number of tuples
1753- * --- bogus, but how to do better?
1754- */
1755- plan -> plan_rows *= 0.1 ;
1756- if (plan -> plan_rows < 1 )
1757- plan -> plan_rows = 1 ;
1747+ /* One output tuple per estimated result group */
1748+ plan -> plan_rows = numGroups ;
17581749
17591750 plan -> state = (EState * ) NULL ;
17601751 plan -> qual = NULL ;
@@ -1786,17 +1777,16 @@ make_unique(List *tlist, Plan *lefttree, List *distinctList)
17861777
17871778 /*
17881779 * Charge one cpu_operator_cost per comparison per input tuple. We
1789- * assume all columns get compared at most of the tuples.
1780+ * assume all columns get compared at most of the tuples. (XXX probably
1781+ * this is an overestimate.)
17901782 */
17911783 plan -> total_cost += cpu_operator_cost * plan -> plan_rows * numCols ;
17921784
17931785 /*
1794- * As for Group, we make the unsupported assumption that there will be
1795- * 10% as many tuples out as in.
1786+ * plan->plan_rows is left as a copy of the input subplan's plan_rows;
1787+ * ie, we assume the filter removes nothing. The caller must alter this
1788+ * if he has a better idea.
17961789 */
1797- plan -> plan_rows *= 0.1 ;
1798- if (plan -> plan_rows < 1 )
1799- plan -> plan_rows = 1 ;
18001790
18011791 plan -> state = (EState * ) NULL ;
18021792 plan -> targetlist = tlist ;
@@ -1850,8 +1840,8 @@ make_setop(SetOpCmd cmd, List *tlist, Plan *lefttree,
18501840 plan -> total_cost += cpu_operator_cost * plan -> plan_rows * numCols ;
18511841
18521842 /*
1853- * As for Group, we make the unsupported assumption that there will be
1854- * 10% as many tuples out as in.
1843+ * We make the unsupported assumption that there will be 10% as many
1844+ * tuples out as in. Any way to do better?
18551845 */
18561846 plan -> plan_rows *= 0.1 ;
18571847 if (plan -> plan_rows < 1 )
0 commit comments