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 2662eca206b94..10596edee4133 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6787,6 +6787,20 @@ func (s *testIntegrationSerialSuite) TestIssue19045(c *C) { tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011")) } +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 *testIntegrationSuite) TestIssue19504(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/types/mydecimal.go b/types/mydecimal.go index ef51758c28297..3a04afa7a4bfe 100644 --- a/types/mydecimal.go +++ b/types/mydecimal.go @@ -2270,6 +2270,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 }