|
15 | 15 | * |
16 | 16 | * |
17 | 17 | * IDENTIFICATION |
18 | | - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.146 2003/09/25 06:58:04 petere Exp $ |
| 18 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.147 2003/10/16 21:37:54 tgl Exp $ |
19 | 19 | * |
20 | 20 | *------------------------------------------------------------------------- |
21 | 21 | */ |
@@ -2166,17 +2166,23 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows) |
2166 | 2166 | } |
2167 | 2167 |
|
2168 | 2168 | /* |
2169 | | - *Clamp to size of rel, multiplybyrestriction selectivity. |
| 2169 | + *Sanity check --- don't dividebyzero if empty relation. |
2170 | 2170 | */ |
2171 | 2171 | Assert(rel->reloptkind==RELOPT_BASEREL); |
2172 | | -if (reldistinct>rel->tuples) |
2173 | | -reldistinct=rel->tuples; |
2174 | | -reldistinct *=rel->rows /rel->tuples; |
| 2172 | +if (rel->tuples>0) |
| 2173 | +{ |
| 2174 | +/* |
| 2175 | + * Clamp to size of rel, multiply by restriction selectivity. |
| 2176 | + */ |
| 2177 | +if (reldistinct>rel->tuples) |
| 2178 | +reldistinct=rel->tuples; |
| 2179 | +reldistinct *=rel->rows /rel->tuples; |
2175 | 2180 |
|
2176 | | -/* |
2177 | | - * Update estimate of total distinct groups. |
2178 | | - */ |
2179 | | -numdistinct *=reldistinct; |
| 2181 | +/* |
| 2182 | + * Update estimate of total distinct groups. |
| 2183 | + */ |
| 2184 | +numdistinct *=reldistinct; |
| 2185 | +} |
2180 | 2186 |
|
2181 | 2187 | varinfos=newvarinfos; |
2182 | 2188 | }while (varinfos!=NIL); |
|