1010 *
1111 *
1212 * IDENTIFICATION
13- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.82 2000/01/27 18:11:30 tgl Exp $
13+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.83 2000/02/03 06:12:18 tgl Exp $
1414 *
1515 *-------------------------------------------------------------------------
1616 */
@@ -743,9 +743,9 @@ create_hashjoin_node(HashPath *best_path,
743743 ** Var nodes representing index keys must have varattno equal to the
744744 * index's attribute number, not the attribute number in the original rel.
745745 ** indxpath.c may have selected an index that is binary-compatible with
746- * the actual expression operator, but not the same; we must replace the
747- * expression's operator with the binary-compatible equivalent operator
748- * that the index will recognize.
746+ * the actual expression operator, but notexactly the same datatype.
747+ *We must replace the expression's operator with the binary-compatible
748+ *equivalent operator that the index will recognize.
749749 ** If the index key is on the right, commute the clause to put it on the
750750 * left. (Someday the executor might not need this, but for now it does.)
751751 *
@@ -1054,6 +1054,7 @@ copy_path_costsize(Plan *dest, Path *src)
10541054 * Copy cost and size info from a lower plan node to an inserted node.
10551055 * This is not critical, since the decisions have already been made,
10561056 * but it helps produce more reasonable-looking EXPLAIN output.
1057+ * (Some callers alter the info after copying it.)
10571058 */
10581059static void
10591060copy_plan_costsize (Plan * dest ,Plan * src )
@@ -1178,12 +1179,7 @@ make_nestloop(List *qptlist,
11781179NestLoop * node = makeNode (NestLoop );
11791180Plan * plan = & node -> join ;
11801181
1181- /*
1182- * this cost estimate is entirely bogus... hopefully it will be
1183- * overwritten by caller.
1184- */
1185- plan -> cost = (lefttree ?lefttree -> cost :0 )+
1186- (righttree ?righttree -> cost :0 );
1182+ /* cost should be inserted by caller */
11871183plan -> state = (EState * )NULL ;
11881184plan -> targetlist = qptlist ;
11891185plan -> qual = qpqual ;
@@ -1204,12 +1200,7 @@ make_hashjoin(List *tlist,
12041200HashJoin * node = makeNode (HashJoin );
12051201Plan * plan = & node -> join ;
12061202
1207- /*
1208- * this cost estimate is entirely bogus... hopefully it will be
1209- * overwritten by caller.
1210- */
1211- plan -> cost = (lefttree ?lefttree -> cost :0 )+
1212- (righttree ?righttree -> cost :0 );
1203+ /* cost should be inserted by caller */
12131204plan -> state = (EState * )NULL ;
12141205plan -> targetlist = tlist ;
12151206plan -> qual = qpqual ;
@@ -1248,12 +1239,7 @@ make_mergejoin(List *tlist,
12481239MergeJoin * node = makeNode (MergeJoin );
12491240Plan * plan = & node -> join ;
12501241
1251- /*
1252- * this cost estimate is entirely bogus... hopefully it will be
1253- * overwritten by caller.
1254- */
1255- plan -> cost = (lefttree ?lefttree -> cost :0 )+
1256- (righttree ?righttree -> cost :0 );
1242+ /* cost should be inserted by caller */
12571243plan -> state = (EState * )NULL ;
12581244plan -> targetlist = tlist ;
12591245plan -> qual = qpqual ;
@@ -1293,6 +1279,7 @@ make_material(List *tlist,
12931279Plan * plan = & node -> plan ;
12941280
12951281copy_plan_costsize (plan ,lefttree );
1282+ /* XXX shouldn't we charge some additional cost for materialization? */
12961283plan -> state = (EState * )NULL ;
12971284plan -> targetlist = tlist ;
12981285plan -> qual = NIL ;
@@ -1310,6 +1297,20 @@ make_agg(List *tlist, Plan *lefttree)
13101297Agg * node = makeNode (Agg );
13111298
13121299copy_plan_costsize (& node -> plan ,lefttree );
1300+ /*
1301+ * The tuple width from the input node is OK, as is the cost (we are
1302+ * ignoring the cost of computing the aggregate; is there any value
1303+ * in accounting for it?). But the tuple count is bogus. We will
1304+ * produce a single tuple if the input is not a Group, and a tuple
1305+ * per group otherwise. For now, estimate the number of groups as
1306+ * 10% of the number of tuples --- bogus, but how to do better?
1307+ * (Note we assume the input Group node is in "tuplePerGroup" mode,
1308+ * so it didn't reduce its row count already.)
1309+ */
1310+ if (IsA (lefttree ,Group ))
1311+ node -> plan .plan_rows *=0.1 ;
1312+ else
1313+ node -> plan .plan_rows = 1 ;
13131314node -> plan .state = (EState * )NULL ;
13141315node -> plan .qual = NULL ;
13151316node -> plan .targetlist = tlist ;
@@ -1329,6 +1330,15 @@ make_group(List *tlist,
13291330Group * node = makeNode (Group );
13301331
13311332copy_plan_costsize (& node -> plan ,lefttree );
1333+ /*
1334+ * If tuplePerGroup (which is named exactly backwards) is true,
1335+ * we will return all the input tuples, so the input node's row count
1336+ * is OK. Otherwise, we'll return only one tuple from each group.
1337+ * For now, estimate the number of groups as 10% of the number of
1338+ * tuples --- bogus, but how to do better?
1339+ */
1340+ if (!tuplePerGroup )
1341+ node -> plan .plan_rows *=0.1 ;
13321342node -> plan .state = (EState * )NULL ;
13331343node -> plan .qual = NULL ;
13341344node -> plan .targetlist = tlist ;
@@ -1357,6 +1367,11 @@ make_unique(List *tlist, Plan *lefttree, List *distinctList)
13571367List * slitem ;
13581368
13591369copy_plan_costsize (plan ,lefttree );
1370+ /*
1371+ * As for Group, we make the unsupported assumption that there will be
1372+ * 10% as many tuples out as in.
1373+ */
1374+ plan -> plan_rows *=0.1 ;
13601375plan -> state = (EState * )NULL ;
13611376plan -> targetlist = tlist ;
13621377plan -> qual = NIL ;