mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Avoid division by zero in estimate_num_groups() when table has no rows.
This commit is contained in:
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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);
|
Assert(rel->reloptkind == RELOPT_BASEREL);
|
||||||
if (reldistinct > rel->tuples)
|
if (rel->tuples > 0)
|
||||||
reldistinct = rel->tuples;
|
{
|
||||||
reldistinct *= rel->rows / rel->tuples;
|
/*
|
||||||
|
* 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.
|
* Update estimate of total distinct groups.
|
||||||
*/
|
*/
|
||||||
numdistinct *= reldistinct;
|
numdistinct *= reldistinct;
|
||||||
|
}
|
||||||
|
|
||||||
varinfos = newvarinfos;
|
varinfos = newvarinfos;
|
||||||
} while (varinfos != NIL);
|
} while (varinfos != NIL);
|
||||||
|
Reference in New Issue
Block a user