From 7690e292c18568f021483ddc43b2a0352be15ccd Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 1 Sep 2020 19:58:24 +0800 Subject: [PATCH] expression: fix incorrect implementation in `builtinRealIsFalseSig` (#19658) * fixup * fixup --- expression/builtin_op_vec.go | 4 ++-- expression/integration_test.go | 14 ++++++++++++++ types/mydecimal.go | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/expression/builtin_op_vec.go b/expression/builtin_op_vec.go index 60b4b85c80b24..d7843eef2fc1e 100644 --- a/expression/builtin_op_vec.go +++ b/expression/builtin_op_vec.go @@ -474,14 +474,14 @@ func (b *builtinRealIsFalseSig) vecEvalInt(input *chunk.Chunk, result *chunk.Col result.ResizeInt64(numRows, false) i64s := result.Int64s() - bufI64s := buf.Int64s() + bufF64s := buf.Float64s() for i := 0; i < numRows; i++ { isNull := buf.IsNull(i) if b.keepNull && isNull { result.SetNull(i, true) continue } - if isNull || bufI64s[i] != 0 { + if isNull || bufF64s[i] != 0 { i64s[i] = 0 } else { i64s[i] = 1 diff --git a/expression/integration_test.go b/expression/integration_test.go index a6204308189b6..aeac09f5ff22d 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7098,6 +7098,20 @@ func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) } +func (s *testIntegrationSerialSuite) TestIssue18674(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustQuery("select -1.0 % -1.0").Check(testkit.Rows("0.0")) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t1(`pk` int primary key,`col_float_key_signed` float ,key (`col_float_key_signed`))") + tk.MustExec("insert into t1 values (0, null), (1, 0), (2, -0), (3, 1), (-1,-1)") + tk.MustQuery("select * from t1 where ( `col_float_key_signed` % `col_float_key_signed`) IS FALSE").Sort().Check(testkit.Rows("-1 -1", "3 1")) + tk.MustQuery("select `col_float_key_signed` , `col_float_key_signed` % `col_float_key_signed` from t1").Sort().Check(testkit.Rows( + "-1 -0", "0 ", "0 ", "1 0", " ")) + tk.MustQuery("select `col_float_key_signed` , (`col_float_key_signed` % `col_float_key_signed`) IS FALSE from t1").Sort().Check(testkit.Rows( + "-1 1", "0 0", "0 0", "1 1", " 0")) +} + func (s *testIntegrationSerialSuite) TestIssue17063(c *C) { collate.SetNewCollationEnabledForTest(true) defer collate.SetNewCollationEnabledForTest(false) diff --git a/types/mydecimal.go b/types/mydecimal.go index 920da505d4960..f86d74206049b 100644 --- a/types/mydecimal.go +++ b/types/mydecimal.go @@ -2281,6 +2281,10 @@ func doDivMod(from1, from2, to, mod *MyDecimal, fracIncr int) error { if idxTo != 0 { copy(to.wordBuf[:], to.wordBuf[idxTo:]) } + + if to.IsZero() { + to.negative = false + } return err }