提交 64c1fc72 编写于 作者: T Tom Lane

Avoid division by zero in estimate_num_groups() when table has no rows.

上级 624292aa
......@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.146 2003/09/25 06:58:04 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.147 2003/10/16 21:37:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -2166,17 +2166,23 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows)
}
/*
* Clamp to size of rel, multiply by restriction selectivity.
* Sanity check --- don't divide by zero if empty relation.
*/
Assert(rel->reloptkind == RELOPT_BASEREL);
if (reldistinct > rel->tuples)
reldistinct = rel->tuples;
reldistinct *= rel->rows / rel->tuples;
if (rel->tuples > 0)
{
/*
* Clamp to size of rel, multiply by restriction selectivity.
*/
if (reldistinct > rel->tuples)
reldistinct = rel->tuples;
reldistinct *= rel->rows / rel->tuples;
/*
* Update estimate of total distinct groups.
*/
numdistinct *= reldistinct;
/*
* Update estimate of total distinct groups.
*/
numdistinct *= reldistinct;
}
varinfos = newvarinfos;
} while (varinfos != NIL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册