From 2daee416f3be66f81a2a89606dc7c42632c09b99 Mon Sep 17 00:00:00 2001 From: sduzh Date: Wed, 6 May 2020 14:04:32 +0800 Subject: [PATCH] expression: keep xor result consistent with mysql 8 (#15934) --- expression/builtin_op.go | 8 ++++++++ expression/builtin_op_test.go | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/expression/builtin_op.go b/expression/builtin_op.go index af4bb78b47b7e..867aebbb25660 100644 --- a/expression/builtin_op.go +++ b/expression/builtin_op.go @@ -179,6 +179,14 @@ func (c *logicXorFunctionClass) getFunction(ctx sessionctx.Context, args []Expre if err != nil { return nil, err } + args[0], err = wrapWithIsTrue(ctx, true, args[0], false) + if err != nil { + return nil, errors.Trace(err) + } + args[1], err = wrapWithIsTrue(ctx, true, args[1], false) + if err != nil { + return nil, errors.Trace(err) + } bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETInt, types.ETInt, types.ETInt) if err != nil { diff --git a/expression/builtin_op_test.go b/expression/builtin_op_test.go index 5ad0c8707d5ac..9055f88449b9b 100644 --- a/expression/builtin_op_test.go +++ b/expression/builtin_op_test.go @@ -589,13 +589,13 @@ func (s *testEvaluatorSuite) TestLogicXor(c *C) { {[]interface{}{0, nil}, 0, true, false}, {[]interface{}{nil, 0}, 0, true, false}, {[]interface{}{nil, 1}, 0, true, false}, - {[]interface{}{0.5000, 0.4999}, 1, false, false}, + {[]interface{}{0.5000, 0.4999}, 0, false, false}, {[]interface{}{0.5000, 1.0}, 0, false, false}, - {[]interface{}{0.4999, 1.0}, 1, false, false}, + {[]interface{}{0.4999, 1.0}, 0, false, false}, {[]interface{}{nil, 0.000}, 0, true, false}, {[]interface{}{nil, 0.001}, 0, true, false}, {[]interface{}{types.NewDecFromStringForTest("0.000001"), 0.00001}, 0, false, false}, - {[]interface{}{types.NewDecFromStringForTest("0.000001"), 1}, 1, false, false}, + {[]interface{}{types.NewDecFromStringForTest("0.000001"), 1}, 0, false, false}, {[]interface{}{types.NewDecFromStringForTest("0.000000"), nil}, 0, true, false}, {[]interface{}{types.NewDecFromStringForTest("0.000001"), nil}, 0, true, false},