statistics: the overflow check is not correct in `0-Math.MinIn… (#11611)

This commit is contained in:
Zhuomin(Charming) Liu
2019-08-05 16:46:31 +08:00
committed by Zhang Jian
parent ddafdff8f7
commit 6dbc8cf651
2 changed files with 11 additions and 3 deletions

View File

@ -195,8 +195,8 @@ func enumRangeValues(low, high types.Datum, lowExclude, highExclude bool) []type
case types.KindInt64:
// Overflow check.
lowVal, highVal := low.GetInt64(), high.GetInt64()
if lowVal < 0 && highVal > 0 {
if lowVal <= -maxNumStep || highVal >= maxNumStep {
if lowVal <= 0 && highVal >= 0 {
if lowVal < -maxNumStep || highVal > maxNumStep {
return nil
}
}

View File

@ -241,11 +241,19 @@ func (s *testStatisticsSuite) TestEnumRangeValues(c *C) {
highExclude: true,
res: "(2017-01-01 00:00:00, 2017-01-01 00:00:01, 2017-01-01 00:00:02, 2017-01-01 00:00:03, 2017-01-01 00:00:04)",
},
// fix issue 11610
{
low: types.NewIntDatum(math.MinInt64),
high: types.NewIntDatum(0),
lowExclude: false,
highExclude: false,
res: "",
},
}
for _, t := range tests {
vals := enumRangeValues(t.low, t.high, t.lowExclude, t.highExclude)
str, err := types.DatumsToString(vals, true)
c.Assert(err, IsNil)
c.Assert(t.res, Equals, str)
c.Assert(str, Equals, t.res)
}
}