Skip to content

Commit

Permalink
statistics: the overflow check is not correct in `0-Math.MinIn… (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored and zz-jason committed Aug 5, 2019
1 parent ddafdff commit 6dbc8cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions statistics/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 9 additions & 1 deletion statistics/scalar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 6dbc8cf

Please sign in to comment.