From e5c8c11b1bba6dcfb00a084d8969041a09b44793 Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Thu, 26 Aug 2021 19:53:18 +0800 Subject: [PATCH 1/7] types: fix incorrect return type about if function when argument type contains bit --- types/field_type.go | 22 +++++++++++----------- types/field_type_test.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/types/field_type.go b/types/field_type.go index 1799ec19392af..efc9c84102548 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -413,7 +413,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeLonglong, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -446,7 +446,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeLonglong, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -479,7 +479,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeLonglong, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -512,7 +512,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeDouble, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -545,7 +545,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeDouble, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -644,7 +644,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeNewDate, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeLonglong, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -677,7 +677,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeNewDate, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeLonglong, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum @@ -892,15 +892,15 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ /* mysql.TypeBit -> */ { // mysql.TypeUnspecified mysql.TypeTiny - mysql.TypeVarchar, mysql.TypeLonglong, + mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeShort mysql.TypeLong - mysql.TypeLonglong, mysql.TypeLonglong, + mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeFloat mysql.TypeDouble - mysql.TypeDouble, mysql.TypeDouble, + mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeNull mysql.TypeTimestamp mysql.TypeBit, mysql.TypeVarchar, // mysql.TypeLonglong mysql.TypeInt24 - mysql.TypeLonglong, mysql.TypeLonglong, + mysql.TypeVarchar, mysql.TypeLonglong, // mysql.TypeDate mysql.TypeTime mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeDatetime mysql.TypeYear diff --git a/types/field_type_test.go b/types/field_type_test.go index 76cc46c33b04e..1b0861e1e0e67 100644 --- a/types/field_type_test.go +++ b/types/field_type_test.go @@ -275,7 +275,7 @@ func (s *testFieldTypeSuite) TestAggFieldType(c *C) { mysql.TypeVarString, mysql.TypeGeometry: c.Assert(aggTp.Tp, Equals, mysql.TypeVarchar) case mysql.TypeBit: - c.Assert(aggTp.Tp, Equals, mysql.TypeLonglong) + c.Assert(aggTp.Tp, Equals, mysql.TypeVarchar) case mysql.TypeString: c.Assert(aggTp.Tp, Equals, mysql.TypeString) case mysql.TypeUnspecified, mysql.TypeNewDecimal: From 55a218f7ffe9c72ca4e8cd5f798e5db640458c1c Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Fri, 27 Aug 2021 10:17:02 +0800 Subject: [PATCH 2/7] types: fix incorrect return type about if function when argument type contains bit, fix bug and add some test --- executor/executor_test.go | 2 +- planner/core/integration_test.go | 15 +++++++++++++++ types/field_type.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index fa917a1845cfb..f7f5888236631 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -1538,7 +1538,7 @@ func (s *testSuiteP2) TestUnion(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a bit(20), b float, c double, d int)") tk.MustExec("insert into t values(10, 10, 10, 10), (1, -1, 2, -2), (2, -2, 1, 1), (2, 1.1, 2.1, 10.1)") - tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("1", "2", "10")) + tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("0x31", "0x3130", "0x32")) } func (s *testSuite2) TestUnionLimit(c *C) { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index e8e6d0862817c..b070c2b6e82f5 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4028,6 +4028,21 @@ func (s *testIntegrationSerialSuite) TestIssue26250(c *C) { tk.MustQuery("select * from tp,tn where tp.id=tn.id and tn.id=1 for update;").Check(testkit.Rows("1 1")) } +func (s *testIntegrationSerialSuite) TestIssue26358(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("CREATE TABLE all_types (\n id int(11) NOT NULL,\n d_tinyint tinyint(4) DEFAULT NULL,\n d_smallint smallint(6) DEFAULT NULL,\n d_int int(11) DEFAULT NULL,\n d_bigint bigint(20) DEFAULT NULL,\n d_float float DEFAULT NULL,\n d_double double DEFAULT NULL,\n d_decimal decimal(10,2) DEFAULT NULL,\n d_bit bit(10) DEFAULT NULL,\n d_binary binary(10) DEFAULT NULL,\n d_date date DEFAULT NULL,\n d_datetime datetime DEFAULT NULL,\n d_timestamp timestamp NULL DEFAULT NULL,\n d_varchar varchar(20) NULL default NULL,\n PRIMARY KEY (id)\n);") + tk.MustExec("insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');") + tk.MustQuery("select d_bit, d_smallint, if(d_bit, d_bit, d_smallint), if(d_bit, d_smallint, d_bit) from all_types;").Check(testkit.Rows("0x000C 1 0x000C 0x31")) + tk.MustQuery("select d_bit, d_tinyint, if(d_bit, d_bit, d_tinyint), if(d_bit, d_tinyint, d_bit) from all_types;").Check(testkit.Rows("0x000C 1 0x000C 0x30")) + tk.MustQuery("select d_bit, d_int, if(d_bit, d_bit, d_int), if(d_bit, d_int, d_bit) from all_types;").Check(testkit.Rows("0x000C 2 0x000C 0x32")) + tk.MustQuery("select d_bit, d_bigint, if(d_bit, d_bit, d_bigint), if(d_bit, d_bigint, d_bit) from all_types;").Check(testkit.Rows("0x000C 3 0x000C 0x33")) + tk.MustQuery("select d_bit, d_float, if(d_bit, d_bit, d_float), if(d_bit, d_float, d_bit) from all_types;").Check(testkit.Rows("0x000C 1.5 0x000C 0x312E35")) + tk.MustQuery("select d_bit, d_double, if(d_bit, d_bit, d_double), if(d_bit, d_double, d_bit) from all_types;").Check(testkit.Rows("0x000C 2.2 0x000C 0x322E32")) + tk.MustQuery("select d_bit, d_decimal, if(d_bit, d_bit, d_decimal), if(d_bit, d_decimal, d_bit) from all_types;").Check(testkit.Rows("0x000C 10.23 0x000C 0x31302E3233")) + tk.MustExec("drop table if exists all_types") +} + func (s *testIntegrationSuite) TestCorrelationAdjustment4Limit(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/types/field_type.go b/types/field_type.go index efc9c84102548..762a66209896c 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -974,7 +974,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{ // mysql.TypeNewDate mysql.TypeVarchar mysql.TypeVarchar, mysql.TypeVarchar, // mysql.TypeBit <16>-<244> - mysql.TypeNewDecimal, + mysql.TypeVarchar, // mysql.TypeJSON mysql.TypeVarchar, // mysql.TypeNewDecimal mysql.TypeEnum From b745738d38638af9bfcdd7acd06065546de4c2df Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Fri, 27 Aug 2021 12:16:05 +0800 Subject: [PATCH 3/7] types: fix incorrect return type about if function when argument type contains bit, fix some test --- executor/executor_test.go | 2 +- planner/core/integration_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index f7f5888236631..01b7b36c778a7 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -1538,7 +1538,7 @@ func (s *testSuiteP2) TestUnion(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a bit(20), b float, c double, d int)") tk.MustExec("insert into t values(10, 10, 10, 10), (1, -1, 2, -2), (2, -2, 1, 1), (2, 1.1, 2.1, 10.1)") - tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("0x31", "0x3130", "0x32")) + tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("\x00\x00\x01", "\x00\x00\x02", "\x00\x00")) } func (s *testSuite2) TestUnionLimit(c *C) { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b070c2b6e82f5..a0c86e32c10fe 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4033,13 +4033,13 @@ func (s *testIntegrationSerialSuite) TestIssue26358(c *C) { tk.MustExec("use test") tk.MustExec("CREATE TABLE all_types (\n id int(11) NOT NULL,\n d_tinyint tinyint(4) DEFAULT NULL,\n d_smallint smallint(6) DEFAULT NULL,\n d_int int(11) DEFAULT NULL,\n d_bigint bigint(20) DEFAULT NULL,\n d_float float DEFAULT NULL,\n d_double double DEFAULT NULL,\n d_decimal decimal(10,2) DEFAULT NULL,\n d_bit bit(10) DEFAULT NULL,\n d_binary binary(10) DEFAULT NULL,\n d_date date DEFAULT NULL,\n d_datetime datetime DEFAULT NULL,\n d_timestamp timestamp NULL DEFAULT NULL,\n d_varchar varchar(20) NULL default NULL,\n PRIMARY KEY (id)\n);") tk.MustExec("insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');") - tk.MustQuery("select d_bit, d_smallint, if(d_bit, d_bit, d_smallint), if(d_bit, d_smallint, d_bit) from all_types;").Check(testkit.Rows("0x000C 1 0x000C 0x31")) - tk.MustQuery("select d_bit, d_tinyint, if(d_bit, d_bit, d_tinyint), if(d_bit, d_tinyint, d_bit) from all_types;").Check(testkit.Rows("0x000C 1 0x000C 0x30")) - tk.MustQuery("select d_bit, d_int, if(d_bit, d_bit, d_int), if(d_bit, d_int, d_bit) from all_types;").Check(testkit.Rows("0x000C 2 0x000C 0x32")) - tk.MustQuery("select d_bit, d_bigint, if(d_bit, d_bit, d_bigint), if(d_bit, d_bigint, d_bit) from all_types;").Check(testkit.Rows("0x000C 3 0x000C 0x33")) - tk.MustQuery("select d_bit, d_float, if(d_bit, d_bit, d_float), if(d_bit, d_float, d_bit) from all_types;").Check(testkit.Rows("0x000C 1.5 0x000C 0x312E35")) - tk.MustQuery("select d_bit, d_double, if(d_bit, d_bit, d_double), if(d_bit, d_double, d_bit) from all_types;").Check(testkit.Rows("0x000C 2.2 0x000C 0x322E32")) - tk.MustQuery("select d_bit, d_decimal, if(d_bit, d_bit, d_decimal), if(d_bit, d_decimal, d_bit) from all_types;").Check(testkit.Rows("0x000C 10.23 0x000C 0x31302E3233")) + tk.MustQuery("select d_bit, d_smallint, if(d_bit, d_bit, d_smallint), if(d_bit, d_smallint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1 \x00\f 1")) + tk.MustQuery("select d_bit, d_tinyint, if(d_bit, d_bit, d_tinyint), if(d_bit, d_tinyint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1 \x00\f 0")) + tk.MustQuery("select d_bit, d_int, if(d_bit, d_bit, d_int), if(d_bit, d_int, d_bit) from all_types;").Check(testkit.Rows("\x00\f 2 \x00\f 2")) + tk.MustQuery("select d_bit, d_bigint, if(d_bit, d_bit, d_bigint), if(d_bit, d_bigint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 3 \x00\f 3")) + tk.MustQuery("select d_bit, d_float, if(d_bit, d_bit, d_float), if(d_bit, d_float, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1.5 \x00\f 1.5")) + tk.MustQuery("select d_bit, d_double, if(d_bit, d_bit, d_double), if(d_bit, d_double, d_bit) from all_types;").Check(testkit.Rows("\x00\f 2.2 \x00\f 2.2")) + tk.MustQuery("select d_bit, d_decimal, if(d_bit, d_bit, d_decimal), if(d_bit, d_decimal, d_bit) from all_types;").Check(testkit.Rows("\x00\f 10.23 \x00\f 10.23")) tk.MustExec("drop table if exists all_types") } From 03a93bd438088a87db68cb8205d2f64b1f116ba4 Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Fri, 27 Aug 2021 14:03:54 +0800 Subject: [PATCH 4/7] types: fix incorrect return type about if function when argument type contains bit, fix test again --- executor/executor_test.go | 2 +- planner/core/integration_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index 01b7b36c778a7..acbda1073724b 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -1538,7 +1538,7 @@ func (s *testSuiteP2) TestUnion(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a bit(20), b float, c double, d int)") tk.MustExec("insert into t values(10, 10, 10, 10), (1, -1, 2, -2), (2, -2, 1, 1), (2, 1.1, 2.1, 10.1)") - tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("\x00\x00\x01", "\x00\x00\x02", "\x00\x00")) + tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("\x00\x00\x01", "\x00\x00\x02", "\x00\x00", "10")) } func (s *testSuite2) TestUnionLimit(c *C) { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index a0c86e32c10fe..ccd9a39150b06 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4034,7 +4034,7 @@ func (s *testIntegrationSerialSuite) TestIssue26358(c *C) { tk.MustExec("CREATE TABLE all_types (\n id int(11) NOT NULL,\n d_tinyint tinyint(4) DEFAULT NULL,\n d_smallint smallint(6) DEFAULT NULL,\n d_int int(11) DEFAULT NULL,\n d_bigint bigint(20) DEFAULT NULL,\n d_float float DEFAULT NULL,\n d_double double DEFAULT NULL,\n d_decimal decimal(10,2) DEFAULT NULL,\n d_bit bit(10) DEFAULT NULL,\n d_binary binary(10) DEFAULT NULL,\n d_date date DEFAULT NULL,\n d_datetime datetime DEFAULT NULL,\n d_timestamp timestamp NULL DEFAULT NULL,\n d_varchar varchar(20) NULL default NULL,\n PRIMARY KEY (id)\n);") tk.MustExec("insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');") tk.MustQuery("select d_bit, d_smallint, if(d_bit, d_bit, d_smallint), if(d_bit, d_smallint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1 \x00\f 1")) - tk.MustQuery("select d_bit, d_tinyint, if(d_bit, d_bit, d_tinyint), if(d_bit, d_tinyint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1 \x00\f 0")) + tk.MustQuery("select d_bit, d_tinyint, if(d_bit, d_bit, d_tinyint), if(d_bit, d_tinyint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 0 \x00\f 0")) tk.MustQuery("select d_bit, d_int, if(d_bit, d_bit, d_int), if(d_bit, d_int, d_bit) from all_types;").Check(testkit.Rows("\x00\f 2 \x00\f 2")) tk.MustQuery("select d_bit, d_bigint, if(d_bit, d_bit, d_bigint), if(d_bit, d_bigint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 3 \x00\f 3")) tk.MustQuery("select d_bit, d_float, if(d_bit, d_bit, d_float), if(d_bit, d_float, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1.5 \x00\f 1.5")) From 8ddde1741a305b2868835576fb6ee90d91b99f68 Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Fri, 27 Aug 2021 14:31:03 +0800 Subject: [PATCH 5/7] types: fix incorrect return type about if function when argument type contains bit, fix test again --- executor/executor_test.go | 2 +- planner/core/integration_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index acbda1073724b..1024066cd6cef 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -1538,7 +1538,7 @@ func (s *testSuiteP2) TestUnion(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a bit(20), b float, c double, d int)") tk.MustExec("insert into t values(10, 10, 10, 10), (1, -1, 2, -2), (2, -2, 1, 1), (2, 1.1, 2.1, 10.1)") - tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("\x00\x00\x01", "\x00\x00\x02", "\x00\x00", "10")) + tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("\x00\x00\x01", "\x00\x00\x02", "\x00\x00\n", "10")) } func (s *testSuite2) TestUnionLimit(c *C) { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index ccd9a39150b06..b005799423ae3 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4039,7 +4039,7 @@ func (s *testIntegrationSerialSuite) TestIssue26358(c *C) { tk.MustQuery("select d_bit, d_bigint, if(d_bit, d_bit, d_bigint), if(d_bit, d_bigint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 3 \x00\f 3")) tk.MustQuery("select d_bit, d_float, if(d_bit, d_bit, d_float), if(d_bit, d_float, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1.5 \x00\f 1.5")) tk.MustQuery("select d_bit, d_double, if(d_bit, d_bit, d_double), if(d_bit, d_double, d_bit) from all_types;").Check(testkit.Rows("\x00\f 2.2 \x00\f 2.2")) - tk.MustQuery("select d_bit, d_decimal, if(d_bit, d_bit, d_decimal), if(d_bit, d_decimal, d_bit) from all_types;").Check(testkit.Rows("\x00\f 10.23 \x00\f 10.23")) + tk.MustQuery("select d_bit, d_decimal, if(d_bit, d_bit, d_decimal), if(d_bit, d_decimal, d_bit) from all_types;").Check(testkit.Rows("\x00\f 10.23 12 10.23")) tk.MustExec("drop table if exists all_types") } From 19be737e8b32890e8ef5479a815ff463a9076fb6 Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Mon, 30 Aug 2021 17:46:44 +0800 Subject: [PATCH 6/7] planner: Fix wrong charset about union result of date type and int, fix schema with wrong collation and charset, Add mock test --- planner/core/integration_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b005799423ae3..a9a428d8539ad 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -3926,6 +3926,34 @@ func (s *testIntegrationSerialSuite) TestIssue25300(c *C) { tk.MustGetErrCode(`(select a from t) union ( select b from t) union select 'a' except select 'd';`, mysql.ErrCantAggregate3collations) } +// TestIssue27167 is just want to test some problem, omit this +func (s *testIntegrationSerialSuite) TestIssue27167(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists all_types") + + tk.MustExec(`CREATE TABLE all_types ( + id int(11) NOT NULL, + d_tinyint tinyint(4) DEFAULT NULL, + d_smallint smallint(6) DEFAULT NULL, + d_int int(11) DEFAULT NULL, + d_bigint bigint(20) DEFAULT NULL, + d_float float DEFAULT NULL, + d_double double DEFAULT NULL, + d_decimal decimal(10,2) DEFAULT NULL, + d_bit bit(10) DEFAULT NULL, + d_binary binary(10) DEFAULT NULL, + d_date date DEFAULT NULL, + d_datetime datetime DEFAULT NULL, + d_timestamp timestamp NULL DEFAULT NULL, + d_varchar varchar(20) NULL default NULL, + PRIMARY KEY (id) + );`) + tk.MustExec(`insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');`) + + tk.MustQuery("select collation(c) from (select d_date c from all_types union select d_int c from all_types) t").Check(testkit.Rows("binary", "binary")) +} + func (s *testIntegrationSerialSuite) TestMergeContinuousSelections(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") From 58e0738585ed03b6e9190cc6b4c094b00256c662 Mon Sep 17 00:00:00 2001 From: yuqi1129 Date: Mon, 30 Aug 2021 18:59:19 +0800 Subject: [PATCH 7/7] planner: Fix wrong charset about union result of date type and int, fix schema with wrong collation and charset, rm mock test --- planner/core/integration_test.go | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index a9a428d8539ad..b005799423ae3 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -3926,34 +3926,6 @@ func (s *testIntegrationSerialSuite) TestIssue25300(c *C) { tk.MustGetErrCode(`(select a from t) union ( select b from t) union select 'a' except select 'd';`, mysql.ErrCantAggregate3collations) } -// TestIssue27167 is just want to test some problem, omit this -func (s *testIntegrationSerialSuite) TestIssue27167(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists all_types") - - tk.MustExec(`CREATE TABLE all_types ( - id int(11) NOT NULL, - d_tinyint tinyint(4) DEFAULT NULL, - d_smallint smallint(6) DEFAULT NULL, - d_int int(11) DEFAULT NULL, - d_bigint bigint(20) DEFAULT NULL, - d_float float DEFAULT NULL, - d_double double DEFAULT NULL, - d_decimal decimal(10,2) DEFAULT NULL, - d_bit bit(10) DEFAULT NULL, - d_binary binary(10) DEFAULT NULL, - d_date date DEFAULT NULL, - d_datetime datetime DEFAULT NULL, - d_timestamp timestamp NULL DEFAULT NULL, - d_varchar varchar(20) NULL default NULL, - PRIMARY KEY (id) - );`) - tk.MustExec(`insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');`) - - tk.MustQuery("select collation(c) from (select d_date c from all_types union select d_int c from all_types) t").Check(testkit.Rows("binary", "binary")) -} - func (s *testIntegrationSerialSuite) TestMergeContinuousSelections(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test")