From 0c55926cf20d18a4a4b40042f12784cfe27d5f9b Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Thu, 12 Mar 2020 19:17:32 +0800 Subject: [PATCH 1/6] fix values_bit_1 --- expression/builtin_other.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/expression/builtin_other.go b/expression/builtin_other.go index e67e6037c6abb..6bec1d300363a 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -14,9 +14,6 @@ package expression import ( - "strings" - "time" - "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/sessionctx" @@ -26,6 +23,8 @@ import ( "github.com/pingcap/tidb/util/set" "github.com/pingcap/tidb/util/stringutil" "github.com/pingcap/tipb/go-tipb" + "strings" + "time" ) var ( @@ -797,6 +796,19 @@ func (b *builtinValuesIntSig) evalInt(_ chunk.Row) (int64, bool, error) { if row.IsNull(b.offset) { return 0, true, nil } + // For BinaryLiteral, see issue #15310 + val := row.GetRaw(b.offset) + if len(val) > 8 { + return 0, true, errors.New("Session current insert values is too long.") + } + if len(val) < 8 { + var binary types.BinaryLiteral = val + v, err := binary.ToInt(b.ctx.GetSessionVars().StmtCtx) + if err != nil { + return 0, true, errors.Trace(err) + } + return int64(v), false, nil + } return row.GetInt64(b.offset), false, nil } return 0, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset) From 56ea87cc4cc6ed04d7093f133e08320bf8411af7 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 13 Mar 2020 10:02:42 +0800 Subject: [PATCH 2/6] add ut --- expression/builtin_other.go | 5 +++-- expression/integration_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/expression/builtin_other.go b/expression/builtin_other.go index 6bec1d300363a..8a0986e2f5aa0 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -14,6 +14,9 @@ package expression import ( + "strings" + "time" + "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/sessionctx" @@ -23,8 +26,6 @@ import ( "github.com/pingcap/tidb/util/set" "github.com/pingcap/tidb/util/stringutil" "github.com/pingcap/tipb/go-tipb" - "strings" - "time" ) var ( diff --git a/expression/integration_test.go b/expression/integration_test.go index aaa68dc85585d..eab55a5149a2a 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5341,6 +5341,19 @@ func (s *testIntegrationSuite) TestCastStrToInt(c *C) { } } +func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { + // See issue #15310 + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("create table t(id int primary key auto_increment, a bit(1));") + tk.MustExec("insert into t values(1,1);") + err := tk.ExecToErr("insert into t values(1,1) on duplicate key update id = values(id),a = values(a);") + c.Assert(err, IsNil) + tk.MustQuery("select a=0 from t;").Check(testkit.Rows("0")) + err = tk.ExecToErr("insert into t values(1,0) on duplicate key update id = values(id),a = values(a);") + c.Assert(err, IsNil) + tk.MustQuery("select a=0 from t;").Check(testkit.Rows("1")) +} + func (s *testIntegrationSuite) TestIssue14159(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.MustExec("DROP TABLE IF EXISTS t") @@ -5867,3 +5880,5 @@ func (s *testIntegrationSerialSuite) TestCollateSubQuery(c *C) { tk.MustQuery("select id from t where not exists (select 1 from t_bin where t_bin.v=t.v) order by id").Check(testkit.Rows()) tk.MustQuery("select id from t_bin where not exists (select 1 from t where t_bin.v=t.v) order by id").Check(testkit.Rows()) } + + From a3d359ff8e39396278c3358fe788b94eac52f7d5 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 13 Mar 2020 10:38:57 +0800 Subject: [PATCH 3/6] make gofmt happy --- expression/integration_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index eab55a5149a2a..40125458ff30b 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5880,5 +5880,3 @@ func (s *testIntegrationSerialSuite) TestCollateSubQuery(c *C) { tk.MustQuery("select id from t where not exists (select 1 from t_bin where t_bin.v=t.v) order by id").Check(testkit.Rows()) tk.MustQuery("select id from t_bin where not exists (select 1 from t where t_bin.v=t.v) order by id").Check(testkit.Rows()) } - - From 4015e969e906093ba8ee46c939f0063c303abca6 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 13 Mar 2020 11:11:35 +0800 Subject: [PATCH 4/6] make lint happy --- expression/builtin_other.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/builtin_other.go b/expression/builtin_other.go index 8a0986e2f5aa0..e90c5d31e6016 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -800,7 +800,7 @@ func (b *builtinValuesIntSig) evalInt(_ chunk.Row) (int64, bool, error) { // For BinaryLiteral, see issue #15310 val := row.GetRaw(b.offset) if len(val) > 8 { - return 0, true, errors.New("Session current insert values is too long.") + return 0, true, errors.New("Session current insert values is too long") } if len(val) < 8 { var binary types.BinaryLiteral = val From 7829f0c66f62a462c75aec399ef388d3dc0afada Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 13 Mar 2020 11:15:48 +0800 Subject: [PATCH 5/6] fix --- expression/integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index 40125458ff30b..c0bd0115095bd 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5344,6 +5344,7 @@ func (s *testIntegrationSuite) TestCastStrToInt(c *C) { func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { // See issue #15310 tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test;") tk.MustExec("create table t(id int primary key auto_increment, a bit(1));") tk.MustExec("insert into t values(1,1);") err := tk.ExecToErr("insert into t values(1,1) on duplicate key update id = values(id),a = values(a);") @@ -5352,6 +5353,7 @@ func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { err = tk.ExecToErr("insert into t values(1,0) on duplicate key update id = values(id),a = values(a);") c.Assert(err, IsNil) tk.MustQuery("select a=0 from t;").Check(testkit.Rows("1")) + tk.MustExec("drop table t;") } func (s *testIntegrationSuite) TestIssue14159(c *C) { From fa141724cc6771972d695d7ca745788866265cee Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 13 Mar 2020 11:23:26 +0800 Subject: [PATCH 6/6] fix --- expression/integration_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index c0bd0115095bd..a8fd44bf55358 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5345,15 +5345,15 @@ func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { // See issue #15310 tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") - tk.MustExec("create table t(id int primary key auto_increment, a bit(1));") - tk.MustExec("insert into t values(1,1);") - err := tk.ExecToErr("insert into t values(1,1) on duplicate key update id = values(id),a = values(a);") + tk.MustExec("create table testValuesBinary(id int primary key auto_increment, a bit(1));") + tk.MustExec("insert into testValuesBinary values(1,1);") + err := tk.ExecToErr("insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a);") c.Assert(err, IsNil) - tk.MustQuery("select a=0 from t;").Check(testkit.Rows("0")) - err = tk.ExecToErr("insert into t values(1,0) on duplicate key update id = values(id),a = values(a);") + tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("0")) + err = tk.ExecToErr("insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a);") c.Assert(err, IsNil) - tk.MustQuery("select a=0 from t;").Check(testkit.Rows("1")) - tk.MustExec("drop table t;") + tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("1")) + tk.MustExec("drop table testValuesBinary;") } func (s *testIntegrationSuite) TestIssue14159(c *C) {