From 0716ab9bb28e18820d963bd478bffbdba9f06ff0 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 9 Oct 2020 14:01:39 +0800 Subject: [PATCH 1/2] cherry pick #20274 to release-4.0 Signed-off-by: ti-srebot --- expression/collation.go | 6 +- expression/integration_test.go | 108 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 3 deletions(-) diff --git a/expression/collation.go b/expression/collation.go index c449f1fb7a6a0..29821094efca4 100644 --- a/expression/collation.go +++ b/expression/collation.go @@ -140,7 +140,7 @@ func deriveCoercibilityForScarlarFunc(sf *ScalarFunction) Coercibility { if _, ok := sysConstFuncs[sf.FuncName.L]; ok { return CoercibilitySysconst } - if !types.IsString(sf.RetType.Tp) { + if sf.RetType.EvalType() != types.ETString { return CoercibilityNumeric } coer := CoercibilityIgnorable @@ -155,14 +155,14 @@ func deriveCoercibilityForScarlarFunc(sf *ScalarFunction) Coercibility { func deriveCoercibilityForConstant(c *Constant) Coercibility { if c.Value.IsNull() { return CoercibilityIgnorable - } else if !types.IsString(c.RetType.Tp) { + } else if c.RetType.EvalType() != types.ETString { return CoercibilityNumeric } return CoercibilityCoercible } func deriveCoercibilityForColumn(c *Column) Coercibility { - if !types.IsString(c.RetType.Tp) { + if c.RetType.EvalType() != types.ETString { return CoercibilityNumeric } return CoercibilityImplicit diff --git a/expression/integration_test.go b/expression/integration_test.go index c45990245334e..8f89c84aeb685 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6676,6 +6676,114 @@ func (s *testIntegrationSuite) TestIssue17727(c *C) { tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) } +<<<<<<< HEAD +======= +func (s *testIntegrationSerialSuite) TestIssue17891(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');") + tk.MustExec("drop table t") + tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');") +} + +func (s *testIntegrationSerialSuite) TestIssue20268(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("CREATE TABLE `t` ( `a` enum('a','b') DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;") + tk.MustExec("insert into t values('a');") + tk.MustExec("select * from t where a = 'A';") +} + +func (s *testIntegrationSerialSuite) TestIssue17233(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists table_int") + tk.MustExec(`CREATE TABLE table_int ( + id_0 int(16) NOT NULL AUTO_INCREMENT, + col_int_0 int(16) DEFAULT NULL, + PRIMARY KEY (id_0), + KEY fvclc (id_0,col_int_0));`) + tk.MustExec("INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0)") + + tk.MustExec("drop table if exists table_varchar") + tk.MustExec(`CREATE TABLE table_varchar ( + id_2 int(16) NOT NULL AUTO_INCREMENT, + col_varchar_2 varchar(511) DEFAULT NULL, + PRIMARY KEY (id_2));`) + tk.MustExec(`INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,'');`) + + tk.MustExec("drop table if exists table_float_varchar") + tk.MustExec(`CREATE TABLE table_int_float_varchar ( + id_6 int(16) NOT NULL AUTO_INCREMENT, + col_int_6 int(16) NOT NULL, + col_float_6 float DEFAULT NULL, + col_varchar_6 varchar(511) DEFAULT NULL, + PRIMARY KEY (id_6,col_int_6) + ) + PARTITION BY RANGE ( col_int_6 ) ( + PARTITION p0 VALUES LESS THAN (1), + PARTITION p2 VALUES LESS THAN (1000), + PARTITION p3 VALUES LESS THAN (10000), + PARTITION p5 VALUES LESS THAN (1000000), + PARTITION p7 VALUES LESS THAN (100000000), + PARTITION p9 VALUES LESS THAN (10000000000), + PARTITION p10 VALUES LESS THAN (100000000000), + PARTITION pn VALUES LESS THAN (MAXVALUE));`) + tk.MustExec(`INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1');`) + + tk.MustExec("drop table if exists table_float") + tk.MustExec(`CREATE TABLE table_float ( + id_1 int(16) NOT NULL AUTO_INCREMENT, + col_float_1 float DEFAULT NULL, + PRIMARY KEY (id_1), + KEY zbjus (id_1,col_float_1));`) + tk.MustExec(`INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1);`) + + tk.MustExec("drop view if exists view_4") + tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS + SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ + tmp1.id_6 AS col_1, + tmp1.col_int_6 AS col_2, + tmp1.col_float_6 AS col_3, + tmp1.col_varchar_6 AS col_4, + tmp2.id_2 AS col_5, + tmp2.col_varchar_2 AS col_6, + tmp3.id_0 AS col_7, + tmp3.col_int_0 AS col_8, + tmp4.id_1 AS col_9, + tmp4.col_float_1 AS col_10 + FROM (( + test.table_int_float_varchar AS tmp1 LEFT JOIN + test.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL + ) JOIN + test.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) + JOIN + test.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5;`) + + tk.MustExec("drop view if exists view_10") + tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS + SELECT table_int.id_0 AS col_1, + table_int.col_int_0 AS col_2 + FROM test.table_int + WHERE + ((-1e+00=1) OR (0e+00>=table_int.col_int_0)) + ORDER BY col_1,col_2 + LIMIT 5,9;`) + + tk.MustQuery("SELECT col_1 FROM test.view_10").Sort().Check(testkit.Rows("16", "18", "19")) + tk.MustQuery("SELECT col_1 FROM test.view_4").Sort().Check(testkit.Rows("8", "8", "8", "8", "8")) + tk.MustQuery("SELECT view_10.col_1 FROM view_4 JOIN view_10").Check(testkit.Rows("16", "16", "16", "16", "16", "18", "18", "18", "18", "18", "19", "19", "19", "19", "19")) +} + +>>>>>>> 2f8092ea8... expression: fix a bug that the coercibilities of enum and set are wrong (#20274) func (s *testIntegrationSuite) TestIssue18515(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") From 7a6426147b23682903dfa8a5c0d78f4e31255aef Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 9 Oct 2020 14:40:29 +0800 Subject: [PATCH 2/2] Update integration_test.go --- expression/integration_test.go | 96 ---------------------------------- 1 file changed, 96 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 8f89c84aeb685..63d18a0cd0ecf 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6676,20 +6676,6 @@ func (s *testIntegrationSuite) TestIssue17727(c *C) { tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) } -<<<<<<< HEAD -======= -func (s *testIntegrationSerialSuite) TestIssue17891(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');") - tk.MustExec("drop table t") - tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');") -} - func (s *testIntegrationSerialSuite) TestIssue20268(c *C) { collate.SetNewCollationEnabledForTest(true) defer collate.SetNewCollationEnabledForTest(false) @@ -6702,88 +6688,6 @@ func (s *testIntegrationSerialSuite) TestIssue20268(c *C) { tk.MustExec("select * from t where a = 'A';") } -func (s *testIntegrationSerialSuite) TestIssue17233(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists table_int") - tk.MustExec(`CREATE TABLE table_int ( - id_0 int(16) NOT NULL AUTO_INCREMENT, - col_int_0 int(16) DEFAULT NULL, - PRIMARY KEY (id_0), - KEY fvclc (id_0,col_int_0));`) - tk.MustExec("INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0)") - - tk.MustExec("drop table if exists table_varchar") - tk.MustExec(`CREATE TABLE table_varchar ( - id_2 int(16) NOT NULL AUTO_INCREMENT, - col_varchar_2 varchar(511) DEFAULT NULL, - PRIMARY KEY (id_2));`) - tk.MustExec(`INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,'');`) - - tk.MustExec("drop table if exists table_float_varchar") - tk.MustExec(`CREATE TABLE table_int_float_varchar ( - id_6 int(16) NOT NULL AUTO_INCREMENT, - col_int_6 int(16) NOT NULL, - col_float_6 float DEFAULT NULL, - col_varchar_6 varchar(511) DEFAULT NULL, - PRIMARY KEY (id_6,col_int_6) - ) - PARTITION BY RANGE ( col_int_6 ) ( - PARTITION p0 VALUES LESS THAN (1), - PARTITION p2 VALUES LESS THAN (1000), - PARTITION p3 VALUES LESS THAN (10000), - PARTITION p5 VALUES LESS THAN (1000000), - PARTITION p7 VALUES LESS THAN (100000000), - PARTITION p9 VALUES LESS THAN (10000000000), - PARTITION p10 VALUES LESS THAN (100000000000), - PARTITION pn VALUES LESS THAN (MAXVALUE));`) - tk.MustExec(`INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1');`) - - tk.MustExec("drop table if exists table_float") - tk.MustExec(`CREATE TABLE table_float ( - id_1 int(16) NOT NULL AUTO_INCREMENT, - col_float_1 float DEFAULT NULL, - PRIMARY KEY (id_1), - KEY zbjus (id_1,col_float_1));`) - tk.MustExec(`INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1);`) - - tk.MustExec("drop view if exists view_4") - tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS - SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ - tmp1.id_6 AS col_1, - tmp1.col_int_6 AS col_2, - tmp1.col_float_6 AS col_3, - tmp1.col_varchar_6 AS col_4, - tmp2.id_2 AS col_5, - tmp2.col_varchar_2 AS col_6, - tmp3.id_0 AS col_7, - tmp3.col_int_0 AS col_8, - tmp4.id_1 AS col_9, - tmp4.col_float_1 AS col_10 - FROM (( - test.table_int_float_varchar AS tmp1 LEFT JOIN - test.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL - ) JOIN - test.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) - JOIN - test.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5;`) - - tk.MustExec("drop view if exists view_10") - tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS - SELECT table_int.id_0 AS col_1, - table_int.col_int_0 AS col_2 - FROM test.table_int - WHERE - ((-1e+00=1) OR (0e+00>=table_int.col_int_0)) - ORDER BY col_1,col_2 - LIMIT 5,9;`) - - tk.MustQuery("SELECT col_1 FROM test.view_10").Sort().Check(testkit.Rows("16", "18", "19")) - tk.MustQuery("SELECT col_1 FROM test.view_4").Sort().Check(testkit.Rows("8", "8", "8", "8", "8")) - tk.MustQuery("SELECT view_10.col_1 FROM view_4 JOIN view_10").Check(testkit.Rows("16", "16", "16", "16", "16", "18", "18", "18", "18", "18", "19", "19", "19", "19", "19")) -} - ->>>>>>> 2f8092ea8... expression: fix a bug that the coercibilities of enum and set are wrong (#20274) func (s *testIntegrationSuite) TestIssue18515(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test")