From 2f9c24be284a28126074b822a024545249289a16 Mon Sep 17 00:00:00 2001 From: sduzh Date: Tue, 31 Mar 2020 22:58:33 +0800 Subject: [PATCH 1/2] expression: keep xor result consistent with mysql 8 (#12867) --- 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 602582ec74da6..daa9564871451 100644 --- a/expression/builtin_op.go +++ b/expression/builtin_op.go @@ -173,6 +173,14 @@ func (c *logicXorFunctionClass) getFunction(ctx sessionctx.Context, args []Expre if err != nil { return nil, err } + args[0], err = wrapWithIsTrue(ctx, true, args[0]) + if err != nil { + return nil, errors.Trace(err) + } + args[1], err = wrapWithIsTrue(ctx, true, args[1]) + if err != nil { + return nil, errors.Trace(err) + } bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETInt, types.ETInt, types.ETInt) sig := &builtinLogicXorSig{bf} diff --git a/expression/builtin_op_test.go b/expression/builtin_op_test.go index 80df488338fd8..94f88c38dddab 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}, From b9b32919b3bbb34523e2b596723e94ed705cb9ae Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Wed, 29 Apr 2020 20:58:15 +0800 Subject: [PATCH 2/2] align to master --- expression/builtin_op.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expression/builtin_op.go b/expression/builtin_op.go index ec252922ae718..867aebbb25660 100644 --- a/expression/builtin_op.go +++ b/expression/builtin_op.go @@ -179,11 +179,11 @@ func (c *logicXorFunctionClass) getFunction(ctx sessionctx.Context, args []Expre if err != nil { return nil, err } - args[0], err = wrapWithIsTrue(ctx, true, args[0]) + 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]) + args[1], err = wrapWithIsTrue(ctx, true, args[1], false) if err != nil { return nil, errors.Trace(err) }