From 6dbc8cf651c2bdcdcc507e852247b38441a3450a Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Mon, 5 Aug 2019 16:46:31 +0800 Subject: [PATCH] =?UTF-8?q?statistics:=20the=20overflow=20check=20is=20not?= =?UTF-8?q?=20correct=20in=20`0-Math.MinIn=E2=80=A6=20(#11611)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statistics/scalar.go | 4 ++-- statistics/scalar_test.go | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/statistics/scalar.go b/statistics/scalar.go index 42b98143e9..53073e1696 100644 --- a/statistics/scalar.go +++ b/statistics/scalar.go @@ -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 } } diff --git a/statistics/scalar_test.go b/statistics/scalar_test.go index ee91e935a5..adafa96fb0 100644 --- a/statistics/scalar_test.go +++ b/statistics/scalar_test.go @@ -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) } }