From 4117ed88fd496334c9ed415057912068b8f80ec6 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 12 Mar 2021 20:00:55 +0800 Subject: [PATCH 1/2] cherry pick #23217 to release-4.0 Signed-off-by: ti-srebot --- expression/integration_test.go | 40 ++++++++++++++++++++++++++++++++++ planner/core/point_get_plan.go | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index fb2bbfbbf1cca..72c3adb568fa7 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6076,6 +6076,46 @@ func (s *testIntegrationSerialSuite) TestCollationBasic(c *C) { tk.MustQuery("select * from t_ci where a='A'").Check(testkit.Rows("a")) tk.MustQuery("select * from t_ci where a='a '").Check(testkit.Rows("a")) tk.MustQuery("select * from t_ci where a='a '").Check(testkit.Rows("a")) +<<<<<<< HEAD +======= + + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a varchar(10) primary key,b int)") + tk.MustExec("insert into t values ('a', 1), ('b', 3), ('a', 2) on duplicate key update b = b + 1;") + tk.MustExec("set autocommit=0") + tk.MustExec("insert into t values ('a', 1), ('b', 3), ('a', 2) on duplicate key update b = b + 1;") + tk.MustQuery("select * from t").Check(testkit.Rows("a 4", "b 4")) + tk.MustExec("set autocommit=1") + tk.MustQuery("select * from t").Check(testkit.Rows("a 4", "b 4")) + + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a varchar(10),b int, key tk (a))") + tk.MustExec("insert into t values ('', 1), ('', 3)") + tk.MustExec("set autocommit=0") + tk.MustExec("update t set b = b + 1") + tk.MustQuery("select * from t").Check(testkit.Rows(" 2", " 4")) + tk.MustExec("set autocommit=1") + tk.MustQuery("select * from t").Check(testkit.Rows(" 2", " 4")) + + tk.MustExec("drop table t_ci") + tk.MustExec("create table t_ci(id bigint primary key, a varchar(10) collate utf8mb4_general_ci, unique key(a, id))") + tk.MustExec("insert into t_ci values (1, 'a')") + tk.MustQuery("select a from t_ci").Check(testkit.Rows("a")) + tk.MustQuery("select a from t_ci").Check(testkit.Rows("a")) + tk.MustQuery("select a from t_ci where a='a'").Check(testkit.Rows("a")) + tk.MustQuery("select a from t_ci where a='A'").Check(testkit.Rows("a")) + tk.MustQuery("select a from t_ci where a='a '").Check(testkit.Rows("a")) + tk.MustQuery("select a from t_ci where a='a '").Check(testkit.Rows("a")) + + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(c set('A', 'B') collate utf8mb4_general_ci);") + tk.MustExec("insert into t values('a');") + tk.MustExec("insert into t values('B');") + tk.MustQuery("select c from t where c = 'a';").Check(testkit.Rows("A")) + tk.MustQuery("select c from t where c = 'A';").Check(testkit.Rows("A")) + tk.MustQuery("select c from t where c = 'b';").Check(testkit.Rows("B")) + tk.MustQuery("select c from t where c = 'B';").Check(testkit.Rows("B")) +>>>>>>> 689a5983e... planner: fix the bug that wrong collation is used when try fast path for enum or set (#23217) } func (s *testIntegrationSerialSuite) TestWeightString(c *C) { diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index d78400cbc9648..d499a6cf81922 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -1040,7 +1040,8 @@ func getNameValuePairs(stmtCtx *stmtctx.StatementContext, tbl *model.TableInfo, } } // The converted result must be same as original datum. - cmp, err := d.CompareDatum(stmtCtx, &dVal) + // Compare them based on the dVal's type. + cmp, err := dVal.CompareDatum(stmtCtx, &d) if err != nil { return nil, false } else if cmp != 0 { From 0f5df39bc6133d9ee7d86eb76ec63ebc7e055786 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 12 Mar 2021 20:05:21 +0800 Subject: [PATCH 2/2] Update integration_test.go --- expression/integration_test.go | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 72c3adb568fa7..3142f0bf516ff 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6076,36 +6076,6 @@ func (s *testIntegrationSerialSuite) TestCollationBasic(c *C) { tk.MustQuery("select * from t_ci where a='A'").Check(testkit.Rows("a")) tk.MustQuery("select * from t_ci where a='a '").Check(testkit.Rows("a")) tk.MustQuery("select * from t_ci where a='a '").Check(testkit.Rows("a")) -<<<<<<< HEAD -======= - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a varchar(10) primary key,b int)") - tk.MustExec("insert into t values ('a', 1), ('b', 3), ('a', 2) on duplicate key update b = b + 1;") - tk.MustExec("set autocommit=0") - tk.MustExec("insert into t values ('a', 1), ('b', 3), ('a', 2) on duplicate key update b = b + 1;") - tk.MustQuery("select * from t").Check(testkit.Rows("a 4", "b 4")) - tk.MustExec("set autocommit=1") - tk.MustQuery("select * from t").Check(testkit.Rows("a 4", "b 4")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a varchar(10),b int, key tk (a))") - tk.MustExec("insert into t values ('', 1), ('', 3)") - tk.MustExec("set autocommit=0") - tk.MustExec("update t set b = b + 1") - tk.MustQuery("select * from t").Check(testkit.Rows(" 2", " 4")) - tk.MustExec("set autocommit=1") - tk.MustQuery("select * from t").Check(testkit.Rows(" 2", " 4")) - - tk.MustExec("drop table t_ci") - tk.MustExec("create table t_ci(id bigint primary key, a varchar(10) collate utf8mb4_general_ci, unique key(a, id))") - tk.MustExec("insert into t_ci values (1, 'a')") - tk.MustQuery("select a from t_ci").Check(testkit.Rows("a")) - tk.MustQuery("select a from t_ci").Check(testkit.Rows("a")) - tk.MustQuery("select a from t_ci where a='a'").Check(testkit.Rows("a")) - tk.MustQuery("select a from t_ci where a='A'").Check(testkit.Rows("a")) - tk.MustQuery("select a from t_ci where a='a '").Check(testkit.Rows("a")) - tk.MustQuery("select a from t_ci where a='a '").Check(testkit.Rows("a")) tk.MustExec("drop table if exists t") tk.MustExec("create table t(c set('A', 'B') collate utf8mb4_general_ci);") @@ -6115,7 +6085,6 @@ func (s *testIntegrationSerialSuite) TestCollationBasic(c *C) { tk.MustQuery("select c from t where c = 'A';").Check(testkit.Rows("A")) tk.MustQuery("select c from t where c = 'b';").Check(testkit.Rows("B")) tk.MustQuery("select c from t where c = 'B';").Check(testkit.Rows("B")) ->>>>>>> 689a5983e... planner: fix the bug that wrong collation is used when try fast path for enum or set (#23217) } func (s *testIntegrationSerialSuite) TestWeightString(c *C) {