clamp_row_est avoid infinite

Started by jian heover 1 year ago2 messages
#1jian he
jian.universality@gmail.com

hi.

/*
* clamp_row_est
* Force a row-count estimate to a sane value.
*/
double
clamp_row_est(double nrows)
{
/*
* Avoid infinite and NaN row estimates. Costs derived from such values
* are going to be useless. Also force the estimate to be at least one
* row, to make explain output look better and to avoid possible
* divide-by-zero when interpolating costs. Make it an integer, too.
*/
if (nrows > MAXIMUM_ROWCOUNT || isnan(nrows))
nrows = MAXIMUM_ROWCOUNT;
else if (nrows <= 1.0)
nrows = 1.0;
else
nrows = rint(nrows);

return nrows;
}

The comments say `Avoid infinite and NaN`
but actually we only avoid NaN.

Do we need to add isinf(nrows)?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: jian he (#1)
Re: clamp_row_est avoid infinite

jian he <jian.universality@gmail.com> writes:

if (nrows > MAXIMUM_ROWCOUNT || isnan(nrows))
nrows = MAXIMUM_ROWCOUNT;
else if (nrows <= 1.0)
nrows = 1.0;
else
nrows = rint(nrows);

The comments say `Avoid infinite and NaN`
but actually we only avoid NaN.

Really? The IEEE float arithmetic standard says that Inf is
greater than any finite value, and in particular it'd be
greater than MAXIMUM_ROWCOUNT.

regards, tom lane