mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-19 20:00:51 +08:00
Avoid division by zero in estimate_num_groups() when table has no rows.
This commit is contained in:
parent
624292aa35
commit
64c1fc7257
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user