diff --git a/dbms/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h b/dbms/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h index f6ed1f1944f..e529238707d 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionStatisticsSimple.h @@ -116,9 +116,12 @@ struct VarMomentsDecimal Float64 getPopulation(UInt32 scale) const { + if (m0 == 0) + return std::numeric_limits::infinity(); + NativeType tmp; if (common::mulOverflow(m1, m1, tmp) || - common::subOverflow(m2, NativeType(tmp/m0), tmp)) + common::subOverflow(m2, NativeType(tmp / m0), tmp)) throw Exception("Decimal math overflow", ErrorCodes::DECIMAL_OVERFLOW); return convertFromDecimal, DataTypeNumber>(tmp / m0, scale); } @@ -126,11 +129,13 @@ struct VarMomentsDecimal Float64 getSample(UInt32 scale) const { if (m0 == 0) - return std::numeric_limits::quiet_NaN(); + return std::numeric_limits::quiet_NaN(); + if (m0 == 1) + return std::numeric_limits::infinity(); NativeType tmp; if (common::mulOverflow(m1, m1, tmp) || - common::subOverflow(m2, NativeType(tmp/m0), tmp)) + common::subOverflow(m2, NativeType(tmp / m0), tmp)) throw Exception("Decimal math overflow", ErrorCodes::DECIMAL_OVERFLOW); return convertFromDecimal, DataTypeNumber>(tmp / (m0 - 1), scale); }