From 3435aaebbd69c7a56b59245f108a45442fe8c1c0 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 19 Oct 2018 17:52:28 +0800 Subject: [PATCH 01/11] *: change default charset and collation from 'utf8 utf8_bin' to 'utf8mb4 utf8mb4_bin' --- ddl/column_test.go | 2 +- ddl/db_change_test.go | 6 +- ddl/db_test.go | 26 +- ddl/ddl_api.go | 11 +- executor/ddl_test.go | 2 +- executor/executor_test.go | 6 +- executor/show.go | 2 +- executor/show_test.go | 38 +- expression/aggregation/agg_to_pb_test.go | 12 +- expression/aggregation/descriptor.go | 4 +- expression/builtin.go | 8 +- expression/builtin_cast.go | 6 +- expression/builtin_control.go | 8 +- expression/builtin_math_test.go | 4 +- expression/builtin_miscellaneous.go | 3 +- expression/expr_to_pb_test.go | 100 ++-- expression/typeinfer_test.go | 664 +++++++++++------------ infoschema/tables.go | 6 +- infoschema/tables_test.go | 4 +- mysql/charset.go | 16 +- owner/fail_test.go | 6 +- parser/parser.y | 8 +- planner/core/plan_to_pb_test.go | 2 +- planner/core/planbuilder.go | 5 +- server/tidb_test.go | 2 +- sessionctx/variable/sysvar.go | 17 +- store/mockstore/mocktikv/analyze.go | 3 +- table/tables/gen_expr.go | 8 +- types/field_type.go | 6 +- types/field_type_test.go | 2 +- util/charset/charset.go | 5 + 31 files changed, 493 insertions(+), 499 deletions(-) diff --git a/ddl/column_test.go b/ddl/column_test.go index 4eea2c9b862d0..4df3bd5bae88b 100644 --- a/ddl/column_test.go +++ b/ddl/column_test.go @@ -915,7 +915,7 @@ func (s *testColumnSuite) TestModifyColumn(c *C) { {"int", "int unsigned", errUnsupportedModifyColumn.GenWithStackByArgs("length 10 is less than origin 11")}, {"varchar(10)", "text", nil}, {"varbinary(10)", "blob", nil}, - {"text", "blob", errUnsupportedModifyColumn.GenWithStackByArgs("charset binary not match origin utf8")}, + {"text", "blob", errUnsupportedModifyColumn.GenWithStackByArgs("charset binary not match origin utf8mb4")}, {"varchar(10)", "varchar(8)", errUnsupportedModifyColumn.GenWithStackByArgs("length 8 is less than origin 10")}, {"varchar(10)", "varchar(11)", nil}, {"varchar(10) character set utf8 collate utf8_bin", "varchar(10) character set utf8", nil}, diff --git a/ddl/db_change_test.go b/ddl/db_change_test.go index 79837b9765ce9..25d9dae9da92e 100644 --- a/ddl/db_change_test.go +++ b/ddl/db_change_test.go @@ -95,9 +95,9 @@ func (s *testStateChangeSuite) TestShowCreateTable(c *C) { got := result.Rows()[0][1] var expected string if job.Type == model.ActionAddIndex { - expected = "CREATE TABLE `t` (\n `id` int(11) DEFAULT NULL,\n KEY `idx` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected = "CREATE TABLE `t` (\n `id` int(11) DEFAULT NULL,\n KEY `idx` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" } else if job.Type == model.ActionAddColumn { - expected = "CREATE TABLE `t` (\n `id` int(11) DEFAULT NULL,\n KEY `idx` (`id`),\n KEY `idx1` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected = "CREATE TABLE `t` (\n `id` int(11) DEFAULT NULL,\n KEY `idx` (`id`),\n KEY `idx1` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" } if got != expected { checkErr = errors.Errorf("got %s, expected %s", got, expected) @@ -375,7 +375,7 @@ func (s *testStateChangeSuite) TestAppendEnum(c *C) { c.Assert(err.Error(), Equals, "[ddl:203]unsupported modify column the number of enum column's elements is less than the original: 2") failAlterTableSQL2 := "alter table t change c2 c2 int default 0" _, err = s.se.Execute(context.Background(), failAlterTableSQL2) - c.Assert(err.Error(), Equals, "[ddl:203]unsupported modify column charset binary not match origin utf8") + c.Assert(err.Error(), Equals, "[ddl:203]unsupported modify column charset binary not match origin utf8mb4") alterTableSQL := "alter table t change c2 c2 enum('N','Y','A') DEFAULT 'A'" _, err = s.se.Execute(context.Background(), alterTableSQL) c.Assert(err, IsNil) diff --git a/ddl/db_test.go b/ddl/db_test.go index e7a4f3a687fa7..91d4967262528 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -1309,7 +1309,7 @@ func (s *testDBSuite) TestAlterColumn(c *C) { c.Assert(err, NotNil) result := s.tk.MustQuery("show create table mc") createSQL := result.Rows()[0][1] - expected := "CREATE TABLE `mc` (\n `a` int(11) NOT NULL,\n `b` int(11) DEFAULT NULL,\n `c` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected := "CREATE TABLE `mc` (\n `a` int(11) NOT NULL,\n `b` int(11) DEFAULT NULL,\n `c` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) // Change / modify column should preserve index options. @@ -1320,7 +1320,7 @@ func (s *testDBSuite) TestAlterColumn(c *C) { s.mustExec(c, "alter table mc modify column c bigint") // Unique should be preserved result = s.tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] - expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` bigint(20) DEFAULT NULL,\n `c` bigint(20) DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `c` (`c`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` bigint(20) DEFAULT NULL,\n `c` bigint(20) DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `c` (`c`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) // Dropping or keeping auto_increment is allowed, however adding is not allowed. @@ -1329,11 +1329,11 @@ func (s *testDBSuite) TestAlterColumn(c *C) { s.mustExec(c, "alter table mc modify column a bigint auto_increment") // Keeps auto_increment result = s.tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] - expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL AUTO_INCREMENT,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL AUTO_INCREMENT,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" s.mustExec(c, "alter table mc modify column a bigint") // Drops auto_increment result = s.tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] - expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) _, err = s.tk.Exec("alter table mc modify column a bigint auto_increment") // Adds auto_increment should throw error c.Assert(err, NotNil) @@ -1735,7 +1735,7 @@ func (s *testDBSuite) TestCreateTableWithPartition(c *C) { partition p0 values less than (to_seconds('2004-01-01')), partition p1 values less than (to_seconds('2005-01-01')));`) s.tk.MustQuery("show create table t26").Check( - testkit.Rows("t26 CREATE TABLE `t26` (\n `a` date DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin\nPARTITION BY RANGE ( to_seconds(`a`) ) (\n PARTITION p0 VALUES LESS THAN (63240134400),\n PARTITION p1 VALUES LESS THAN (63271756800)\n)")) + testkit.Rows("t26 CREATE TABLE `t26` (\n `a` date DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\nPARTITION BY RANGE ( to_seconds(`a`) ) (\n PARTITION p0 VALUES LESS THAN (63240134400),\n PARTITION p1 VALUES LESS THAN (63271756800)\n)")) s.tk.MustExec(`create table t27 (a bigint unsigned not null) partition by range(a) ( partition p0 values less than (10), @@ -2085,7 +2085,7 @@ func (s *testDBSuite) TestChangeColumnPosition(c *C) { " `c` int(11) DEFAULT NULL,", " `a` int(11) DEFAULT NULL,", " KEY `t` (`c`)", - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", } c.Assert(createSQL, Equals, strings.Join(exceptedSQL, "\n")) } @@ -2104,7 +2104,7 @@ func (s *testDBSuite) TestGeneratedColumnDDL(c *C) { // Check show create table with virtual generated column. result = s.tk.MustQuery(`show create table test_gv_ddl`) result.Check(testkit.Rows( - "test_gv_ddl CREATE TABLE `test_gv_ddl` (\n `a` int(11) DEFAULT NULL,\n `b` int(11) GENERATED ALWAYS AS (`a` + 8) VIRTUAL DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + "test_gv_ddl CREATE TABLE `test_gv_ddl` (\n `a` int(11) DEFAULT NULL,\n `b` int(11) GENERATED ALWAYS AS (`a` + 8) VIRTUAL DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) // Check alter table add a stored generated column. @@ -2118,7 +2118,7 @@ func (s *testDBSuite) TestGeneratedColumnDDL(c *C) { result.Check(testkit.Rows("table_with_gen_col_blanks CREATE TABLE `table_with_gen_col_blanks` (\n" + " `a` int(11) DEFAULT NULL,\n" + " `b` char(20) GENERATED ALWAYS AS (CAST(`a` AS CHAR)) VIRTUAL DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin")) + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) genExprTests := []struct { stmt string @@ -2269,7 +2269,7 @@ func (s *testDBSuite) TestCheckColumnDefaultValue(c *C) { s.tk.MustQuery(`show create table text_default_text`).Check(testutil.RowsWithSep("|", "text_default_text CREATE TABLE `text_default_text` (\n"+ " `c1` text NOT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) ctx := s.tk.Se.(sessionctx.Context) is := domain.GetDomain(ctx).InfoSchema() @@ -2282,7 +2282,7 @@ func (s *testDBSuite) TestCheckColumnDefaultValue(c *C) { s.tk.MustQuery(`show create table text_default_blob`).Check(testutil.RowsWithSep("|", "text_default_blob CREATE TABLE `text_default_blob` (\n"+ " `c1` blob NOT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) is = domain.GetDomain(ctx).InfoSchema() tblInfo, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("text_default_blob")) @@ -2294,7 +2294,7 @@ func (s *testDBSuite) TestCheckColumnDefaultValue(c *C) { s.tk.MustQuery(`show create table text_default_json`).Check(testutil.RowsWithSep("|", "text_default_json CREATE TABLE `text_default_json` (\n"+ " `c1` json NOT NULL DEFAULT 'null'\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) is = domain.GetDomain(ctx).InfoSchema() tblInfo, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("text_default_json")) @@ -2309,8 +2309,8 @@ func (s *testDBSuite) TestCharacterSetInColumns(c *C) { s.tk.MustExec("use varchar_test") s.tk.MustExec("drop table if exists t") s.tk.MustExec("create table t (c1 int, s1 varchar(10), s2 text)") - s.tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name != 'utf8'").Check(testkit.Rows("0")) - s.tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name = 'utf8'").Check(testkit.Rows("2")) + s.tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name != 'utf8mb4'").Check(testkit.Rows("0")) + s.tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name = 'utf8mb4'").Check(testkit.Rows("2")) s.tk.MustExec("drop table if exists t5") s.tk.MustExec("create table t5(id int) charset=UTF8;") diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 70109e9214981..3263fb09e109f 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -65,7 +65,7 @@ func (d *ddl) CreateSchema(ctx sessionctx.Context, schema model.CIStr, charsetIn dbInfo.Charset = charsetInfo.Chs dbInfo.Collate = charsetInfo.Col } else { - dbInfo.Charset, dbInfo.Collate = getDefaultCharsetAndCollate() + dbInfo.Charset, dbInfo.Collate = charset.GetDefaultCharsetAndCollate() } job := &model.Job{ @@ -118,13 +118,6 @@ func checkTooLongIndex(index model.CIStr) error { return nil } -func getDefaultCharsetAndCollate() (string, string) { - // TODO: TableDefaultCharset-->DatabaseDefaultCharset-->SystemDefaultCharset. - // TODO: Change TableOption parser to parse collate. - // This is a tmp solution. - return "utf8", "utf8_bin" -} - func setColumnFlagWithConstraint(colMap map[string]*table.Column, v *ast.Constraint) { switch v.Tp { case ast.ConstraintPrimaryKey: @@ -204,7 +197,7 @@ func setCharsetCollationFlenDecimal(tp *types.FieldType) error { if len(tp.Charset) == 0 { switch tp.Tp { case mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString, mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeEnum, mysql.TypeSet: - tp.Charset, tp.Collate = getDefaultCharsetAndCollate() + tp.Charset, tp.Collate = charset.GetDefaultCharsetAndCollate() default: tp.Charset = charset.CharsetBin tp.Collate = charset.CharsetBin diff --git a/executor/ddl_test.go b/executor/ddl_test.go index b91a57b4b1559..aadf39713542a 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -214,7 +214,7 @@ func (s *testSuite) TestAlterTableModifyColumn(c *C) { tk.MustExec("alter table mc modify column c2 text") result := tk.MustQuery("show create table mc") createSQL := result.Rows()[0][1] - expected := "CREATE TABLE `mc` (\n `c1` bigint(20) DEFAULT NULL,\n `c2` text DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" + expected := "CREATE TABLE `mc` (\n `c1` bigint(20) DEFAULT NULL,\n `c2` text DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) } diff --git a/executor/executor_test.go b/executor/executor_test.go index dcbfec3fbd61b..129897ea6d399 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -992,7 +992,7 @@ func (s *testSuite) TestUnion(c *C) { tk.MustExec("CREATE TABLE t1 (a date)") tk.MustExec("CREATE TABLE t2 (a date)") tk.MustExec("SELECT a from t1 UNION select a FROM t2") - tk.MustQuery("show create table t1").Check(testkit.Rows("t1 CREATE TABLE `t1` (\n" + " `a` date DEFAULT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin")) + tk.MustQuery("show create table t1").Check(testkit.Rows("t1 CREATE TABLE `t1` (\n" + " `a` date DEFAULT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) // Move from session test. tk.MustExec("drop table if exists t1, t2") @@ -1694,8 +1694,8 @@ func (s *testSuite) TestTableScan(c *C) { c.Assert(len(result.Rows()), GreaterEqual, 4) tk.MustExec("use test") tk.MustExec("create database mytest") - rowStr1 := fmt.Sprintf("%s %s %s %s %v", "def", "mysql", "utf8", "utf8_bin", nil) - rowStr2 := fmt.Sprintf("%s %s %s %s %v", "def", "mytest", "utf8", "utf8_bin", nil) + rowStr1 := fmt.Sprintf("%s %s %s %s %v", "def", "mysql", "utf8mb4", "utf8mb4_bin", nil) + rowStr2 := fmt.Sprintf("%s %s %s %s %v", "def", "mytest", "utf8mb4", "utf8mb4_bin", nil) tk.MustExec("use information_schema") result = tk.MustQuery("select * from schemata where schema_name = 'mysql'") result.Check(testkit.Rows(rowStr1)) diff --git a/executor/show.go b/executor/show.go index 0a76e27f683f7..b5d2ef8867833 100644 --- a/executor/show.go +++ b/executor/show.go @@ -593,7 +593,7 @@ func (e *ShowExec) fetchShowCreateTable() error { buf.WriteString(") ENGINE=InnoDB") charsetName := tb.Meta().Charset if len(charsetName) == 0 { - charsetName = charset.CharsetUTF8 + charsetName = charset.CharsetUTF8MB4 } collate := tb.Meta().Collate // Set default collate if collate is not specified. diff --git a/executor/show_test.go b/executor/show_test.go index cf1bbfef8e8de..a773385f836c7 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -73,7 +73,7 @@ func (s *testSuite) TestShow(c *C) { c.Check(result.Rows(), HasLen, 1) row = result.Rows()[0] expectedRow = []interface{}{ - "ptest", "CREATE TABLE `ptest` (\n `a` int(11) NOT NULL,\n `b` double NOT NULL DEFAULT '2.0',\n `c` varchar(10) NOT NULL,\n `d` time DEFAULT NULL,\n `e` timestamp NULL DEFAULT NULL,\n `f` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `d` (`d`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"} + "ptest", "CREATE TABLE `ptest` (\n `a` int(11) NOT NULL,\n `b` double NOT NULL DEFAULT '2.0',\n `c` varchar(10) NOT NULL,\n `d` time DEFAULT NULL,\n `e` timestamp NULL DEFAULT NULL,\n `f` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `d` (`d`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -99,7 +99,7 @@ func (s *testSuite) TestShow(c *C) { " `c3` mediumint(8) UNSIGNED DEFAULT NULL,\n" + " `c4` int(10) UNSIGNED DEFAULT NULL,\n" + " `c5` bigint(20) UNSIGNED DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"} + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -115,7 +115,7 @@ func (s *testSuite) TestShow(c *C) { expectedRow = []interface{}{ "decimalschema", "CREATE TABLE `decimalschema` (\n" + " `c1` decimal(11,0) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"} + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -130,7 +130,7 @@ func (s *testSuite) TestShow(c *C) { expectedRow = []interface{}{ "decimalschema", "CREATE TABLE `decimalschema` (\n" + " `c1` decimal(15,0) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"} + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -199,7 +199,7 @@ func (s *testSuite) TestShow(c *C) { tk.MustExec(testSQL) testSQL = "show create database show_test_DB;" tk.MustQuery(testSQL).Check(testutil.RowsWithSep("|", - "show_test_DB|CREATE DATABASE `show_test_DB` /* !40100 DEFAULT CHARACTER SET utf8 */", + "show_test_DB|CREATE DATABASE `show_test_DB` /* !40100 DEFAULT CHARACTER SET utf8mb4 */", )) tk.MustExec("use show_test_DB") @@ -223,7 +223,7 @@ func (s *testSuite) TestShow(c *C) { "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`id`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=4", )) // for issue https://github.com/pingcap/tidb/issues/4678 autoIDStep := autoid.GetStep() @@ -234,7 +234,7 @@ func (s *testSuite) TestShow(c *C) { "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`id`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT="+strconv.Itoa(int(autoID)), + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT="+strconv.Itoa(int(autoID)), )) tk.MustExec(`drop table show_auto_increment`) tk.MustExec(`create table show_auto_increment (id int primary key auto_increment)`) @@ -243,7 +243,7 @@ func (s *testSuite) TestShow(c *C) { "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`id`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) tk.MustExec("insert into show_auto_increment values(10)") autoID = autoIDStep + 11 @@ -252,7 +252,7 @@ func (s *testSuite) TestShow(c *C) { "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`id`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT="+strconv.Itoa(int(autoID)), + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT="+strconv.Itoa(int(autoID)), )) // Test show table with column's comment contain escape character @@ -263,7 +263,7 @@ func (s *testSuite) TestShow(c *C) { ""+ "show_escape_character CREATE TABLE `show_escape_character` (\n"+ " `id` int(11) DEFAULT NULL COMMENT 'a\\rb\\nc d\\0ef'\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) // for issue https://github.com/pingcap/tidb/issues/4424 @@ -277,7 +277,7 @@ func (s *testSuite) TestShow(c *C) { c.Check(result.Rows(), HasLen, 1) row = result.Rows()[0] expectedRow = []interface{}{ - "show_test", "CREATE TABLE `show_test` (\n `a` varchar(10) DEFAULT NULL COMMENT 'a\\nb\\rc d\\0e'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='a\\nb\\rc d\\0e'"} + "show_test", "CREATE TABLE `show_test` (\n `a` varchar(10) DEFAULT NULL COMMENT 'a\\nb\\rc d\\0e'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='a\\nb\\rc d\\0e'"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -293,7 +293,7 @@ func (s *testSuite) TestShow(c *C) { c.Check(result.Rows(), HasLen, 1) row = result.Rows()[0] expectedRow = []interface{}{ - "show_test", "CREATE TABLE `show_test` (\n `a` varchar(10) DEFAULT 'a\\nb\\rc d\\0e'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"} + "show_test", "CREATE TABLE `show_test` (\n `a` varchar(10) DEFAULT 'a\\nb\\rc d\\0e'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -312,7 +312,7 @@ func (s *testSuite) TestShow(c *C) { c.Check(result.Rows(), HasLen, 1) row = result.Rows()[0] expectedRow = []interface{}{ - "show_test", "CREATE TABLE `show_test` (\n `a` bit(1) DEFAULT NULL,\n `b` bit(32) DEFAULT b'0',\n `c` bit(1) DEFAULT b'1',\n `d` bit(10) DEFAULT b'1010'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"} + "show_test", "CREATE TABLE `show_test` (\n `a` bit(1) DEFAULT NULL,\n `b` bit(32) DEFAULT b'0',\n `c` bit(1) DEFAULT b'1',\n `d` bit(10) DEFAULT b'1010'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -340,7 +340,7 @@ func (s *testSuite) TestShow(c *C) { " `c` mediumint(9) DEFAULT NULL,\n" + " `d` int(11) DEFAULT NULL,\n" + " `e` bigint(20) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", } for i, r := range row { c.Check(r, Equals, expectedRow[i]) @@ -364,7 +364,7 @@ func (s *testSuite) TestShow(c *C) { tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", "t CREATE TABLE `t` (\n"+ " `a` int(11) DEFAULT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"+"\nPARTITION BY RANGE ( `a` ) (\n PARTITION p0 VALUES LESS THAN (10),\n PARTITION p1 VALUES LESS THAN (20),\n PARTITION p2 VALUES LESS THAN (MAXVALUE)\n)", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"+"\nPARTITION BY RANGE ( `a` ) (\n PARTITION p0 VALUES LESS THAN (10),\n PARTITION p1 VALUES LESS THAN (20),\n PARTITION p2 VALUES LESS THAN (MAXVALUE)\n)", )) tk.MustExec(`drop table if exists t`) @@ -387,7 +387,7 @@ func (s *testSuite) TestShow(c *C) { " `b` int(11) DEFAULT NULL,\n"+ " `c` char(1) DEFAULT NULL,\n"+ " `d` int(11) DEFAULT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"+"\nPARTITION BY RANGE COLUMNS(a,d,c) (\n PARTITION p0 VALUES LESS THAN (5,10,\"ggg\"),\n PARTITION p1 VALUES LESS THAN (10,20,\"mmm\"),\n PARTITION p2 VALUES LESS THAN (15,30,\"sss\"),\n PARTITION p3 VALUES LESS THAN (50,MAXVALUE,MAXVALUE)\n)", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"+"\nPARTITION BY RANGE COLUMNS(a,d,c) (\n PARTITION p0 VALUES LESS THAN (5,10,\"ggg\"),\n PARTITION p1 VALUES LESS THAN (10,20,\"mmm\"),\n PARTITION p2 VALUES LESS THAN (15,30,\"sss\"),\n PARTITION p3 VALUES LESS THAN (50,MAXVALUE,MAXVALUE)\n)", )) // Test show create table compression type. @@ -396,7 +396,7 @@ func (s *testSuite) TestShow(c *C) { tk.MustQuery("show create table t1").Check(testutil.RowsWithSep("|", "t1 CREATE TABLE `t1` (\n"+ " `c1` int(11) DEFAULT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMPRESSION='zlib'", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMPRESSION='zlib'", )) // Test show create table year type @@ -407,7 +407,7 @@ func (s *testSuite) TestShow(c *C) { " `y` year NOT NULL,\n"+ " `x` int(11) DEFAULT NULL,\n"+ " PRIMARY KEY (`y`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin")) + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) // Test show create table with zerofill flag tk.MustExec(`drop table if exists t`) @@ -417,7 +417,7 @@ func (s *testSuite) TestShow(c *C) { " `id` int(11) NOT NULL,\n"+ " `val` tinyint(10) UNSIGNED ZEROFILL DEFAULT NULL,\n"+ " PRIMARY KEY (`id`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin")) + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) } func (s *testSuite) TestShowVisibility(c *C) { diff --git a/expression/aggregation/agg_to_pb_test.go b/expression/aggregation/agg_to_pb_test.go index 2a17b120e5394..608d2b8f496d9 100644 --- a/expression/aggregation/agg_to_pb_test.go +++ b/expression/aggregation/agg_to_pb_test.go @@ -88,13 +88,13 @@ func (s *testEvaluatorSuite) TestAggFunc2Pb(c *C) { } jsons := []string{ - `{"tp":3002,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}`, - `{"tp":3001,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}],"sig":0,"field_type":{"tp":8,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}`, - `{"tp":3003,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}`, + `{"tp":3002,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}`, + `{"tp":3001,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}],"sig":0,"field_type":{"tp":8,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}`, + `{"tp":3003,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}`, "null", - `{"tp":3005,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}`, - `{"tp":3004,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}`, - `{"tp":3006,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":83,"charset":""}}`, + `{"tp":3005,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}`, + `{"tp":3004,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}`, + `{"tp":3006,"children":[{"tp":201,"val":"gAAAAAAAAAE=","sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}],"sig":0,"field_type":{"tp":5,"flag":0,"flen":-1,"decimal":-1,"collate":46,"charset":""}}`, } for i, funcName := range funcNames { aggFunc := &AggFuncDesc{ diff --git a/expression/aggregation/descriptor.go b/expression/aggregation/descriptor.go index 7c47ec85c0d64..87f7fca954ea0 100644 --- a/expression/aggregation/descriptor.go +++ b/expression/aggregation/descriptor.go @@ -334,8 +334,8 @@ func (a *AggFuncDesc) typeInfer4Avg(ctx sessionctx.Context) { func (a *AggFuncDesc) typeInfer4GroupConcat(ctx sessionctx.Context) { a.RetTp = types.NewFieldType(mysql.TypeVarString) - a.RetTp.Charset = charset.CharsetUTF8 - a.RetTp.Collate = charset.CollationUTF8 + a.RetTp.Charset = charset.CharsetUTF8MB4 + a.RetTp.Collate = charset.CollationUTF8MB4 a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxBlobWidth, 0 // TODO: a.Args[i] = expression.WrapWithCastAsString(ctx, a.Args[i]) } diff --git a/expression/builtin.go b/expression/builtin.go index ba165008278f9..eeed1c858197e 100644 --- a/expression/builtin.go +++ b/expression/builtin.go @@ -141,15 +141,15 @@ func newBaseBuiltinFuncWithTp(ctx sessionctx.Context, args []Expression, retType Tp: mysql.TypeJSON, Flen: mysql.MaxBlobWidth, Decimal: 0, - Charset: charset.CharsetUTF8, - Collate: charset.CollationUTF8, + Charset: mysql.DefaultCharset, + Collate: mysql.DefaultCollationName, Flag: mysql.BinaryFlag, } } if mysql.HasBinaryFlag(fieldType.Flag) && fieldType.Tp != mysql.TypeJSON { fieldType.Charset, fieldType.Collate = charset.CharsetBin, charset.CollationBin } else { - fieldType.Charset, fieldType.Collate = charset.CharsetUTF8, charset.CharsetUTF8 + fieldType.Charset, fieldType.Collate = mysql.DefaultCharset, mysql.DefaultCollationName } return baseBuiltinFunc{ args: args, @@ -199,7 +199,7 @@ func (b *baseBuiltinFunc) getRetTp() *types.FieldType { b.tp.Tp = mysql.TypeMediumBlob } if len(b.tp.Charset) <= 0 { - b.tp.Charset, b.tp.Collate = charset.CharsetUTF8, charset.CollationUTF8 + b.tp.Charset, b.tp.Collate = mysql.DefaultCharset, mysql.DefaultCollationName } } return b.tp diff --git a/expression/builtin_cast.go b/expression/builtin_cast.go index f30437dc0c39a..9fe6b8702fe99 100644 --- a/expression/builtin_cast.go +++ b/expression/builtin_cast.go @@ -1741,7 +1741,7 @@ func WrapWithCastAsString(ctx sessionctx.Context, expr Expression) Expression { argLen = mysql.MaxIntWidth } tp := types.NewFieldType(mysql.TypeVarString) - tp.Charset, tp.Collate = charset.CharsetUTF8, charset.CollationUTF8 + tp.Charset, tp.Collate = charset.CharsetUTF8MB4, charset.CollationUTF8MB4 tp.Flen, tp.Decimal = argLen, types.UnspecifiedLength return BuildCastFunction(ctx, expr, tp) } @@ -1804,8 +1804,8 @@ func WrapWithCastAsJSON(ctx sessionctx.Context, expr Expression) Expression { Tp: mysql.TypeJSON, Flen: 12582912, // FIXME: Here the Flen is not trusted. Decimal: 0, - Charset: charset.CharsetUTF8, - Collate: charset.CollationUTF8, + Charset: charset.CharsetUTF8MB4, + Collate: charset.CollationUTF8MB4, Flag: mysql.BinaryFlag, } return BuildCastFunction(ctx, expr, tp) diff --git a/expression/builtin_control.go b/expression/builtin_control.go index 9900a22bed4a8..9ae0e90909eb0 100644 --- a/expression/builtin_control.go +++ b/expression/builtin_control.go @@ -81,19 +81,19 @@ func inferType4ControlFuncs(lhs, rhs *types.FieldType) *types.FieldType { } } if types.IsNonBinaryStr(lhs) && !types.IsBinaryStr(rhs) { - resultFieldType.Charset, resultFieldType.Collate, resultFieldType.Flag = charset.CharsetUTF8, charset.CollationUTF8, 0 + resultFieldType.Charset, resultFieldType.Collate, resultFieldType.Flag = charset.CharsetUTF8MB4, charset.CollationUTF8MB4, 0 if mysql.HasBinaryFlag(lhs.Flag) || !types.IsNonBinaryStr(rhs) { resultFieldType.Flag |= mysql.BinaryFlag } } else if types.IsNonBinaryStr(rhs) && !types.IsBinaryStr(lhs) { - resultFieldType.Charset, resultFieldType.Collate, resultFieldType.Flag = charset.CharsetUTF8, charset.CollationUTF8, 0 + resultFieldType.Charset, resultFieldType.Collate, resultFieldType.Flag = charset.CharsetUTF8MB4, charset.CollationUTF8MB4, 0 if mysql.HasBinaryFlag(rhs.Flag) || !types.IsNonBinaryStr(lhs) { resultFieldType.Flag |= mysql.BinaryFlag } } else if types.IsBinaryStr(lhs) || types.IsBinaryStr(rhs) || !evalType.IsStringKind() { types.SetBinChsClnFlag(resultFieldType) } else { - resultFieldType.Charset, resultFieldType.Collate, resultFieldType.Flag = charset.CharsetUTF8, charset.CollationUTF8, 0 + resultFieldType.Charset, resultFieldType.Collate, resultFieldType.Flag = mysql.DefaultCharset, mysql.DefaultCollationName, 0 } if evalType == types.ETDecimal || evalType == types.ETInt { lhsUnsignedFlag, rhsUnsignedFlag := mysql.HasUnsignedFlag(lhs.Flag), mysql.HasUnsignedFlag(rhs.Flag) @@ -164,7 +164,7 @@ func (c *caseWhenFunctionClass) getFunction(ctx sessionctx.Context, args []Expre } fieldTp.Decimal, fieldTp.Flen = decimal, flen if fieldTp.EvalType().IsStringKind() && !isBinaryStr { - fieldTp.Charset, fieldTp.Collate = mysql.DefaultCharset, mysql.DefaultCollationName + fieldTp.Charset, fieldTp.Collate = charset.CharsetUTF8MB4, charset.CollationUTF8MB4 } if isBinaryFlag { fieldTp.Flag |= mysql.BinaryFlag diff --git a/expression/builtin_math_test.go b/expression/builtin_math_test.go index a0c291603a5c3..4c64681d4d8cc 100644 --- a/expression/builtin_math_test.go +++ b/expression/builtin_math_test.go @@ -556,8 +556,8 @@ func (s *testEvaluatorSuite) TestConv(c *C) { c.Assert(err, IsNil) tp := f.GetType() c.Assert(tp.Tp, Equals, mysql.TypeVarString) - c.Assert(tp.Charset, Equals, charset.CharsetUTF8) - c.Assert(tp.Collate, Equals, charset.CharsetUTF8) + c.Assert(tp.Charset, Equals, charset.CharsetUTF8MB4) + c.Assert(tp.Collate, Equals, charset.CollationUTF8MB4) c.Assert(tp.Flag, Equals, uint(0)) d, err := f.Eval(chunk.Row{}) diff --git a/expression/builtin_miscellaneous.go b/expression/builtin_miscellaneous.go index b249551247340..f8c4200edf1e8 100644 --- a/expression/builtin_miscellaneous.go +++ b/expression/builtin_miscellaneous.go @@ -25,7 +25,6 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" - "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pkg/errors" "github.com/twinj/uuid" @@ -227,7 +226,7 @@ func (c *anyValueFunctionClass) getFunction(ctx sessionctx.Context, args []Expre bf.tp.Decimal = types.UnspecifiedLength sig = &builtinStringAnyValueSig{bf} case types.ETDatetime, types.ETTimestamp: - bf.tp.Charset, bf.tp.Collate, bf.tp.Flag = charset.CharsetUTF8, charset.CollationUTF8, 0 + bf.tp.Charset, bf.tp.Collate, bf.tp.Flag = mysql.DefaultCharset, mysql.DefaultCollationName, 0 sig = &builtinTimeAnyValueSig{bf} default: panic("unexpected types.EvalType of builtin function ANY_VALUE") diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go index a4d96e571411d..947f9378e3c6c 100644 --- a/expression/expr_to_pb_test.go +++ b/expression/expr_to_pb_test.go @@ -173,31 +173,31 @@ func (s *testEvaluatorSuite) TestColumn2Pb(c *C) { c.Assert(len(remained), Equals, 0) js, err := json.Marshal(pbExpr) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":2,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAQ=\",\"sig\":0,\"field_type\":{\"tp\":4,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAU=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAY=\",\"sig\":0,\"field_type\":{\"tp\":6,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAc=\",\"sig\":0,\"field_type\":{\"tp\":7,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAg=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAk=\",\"sig\":0,\"field_type\":{\"tp\":9,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAo=\",\"sig\":0,\"field_type\":{\"tp\":10,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAs=\",\"sig\":0,\"field_type\":{\"tp\":11,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAw=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAA0=\",\"sig\":0,\"field_type\":{\"tp\":13,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAA8=\",\"sig\":0,\"field_type\":{\"tp\":15,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABA=\",\"sig\":0,\"field_type\":{\"tp\":245,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABE=\",\"sig\":0,\"field_type\":{\"tp\":246,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABI=\",\"sig\":0,\"field_type\":{\"tp\":249,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABM=\",\"sig\":0,\"field_type\":{\"tp\":250,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABQ=\",\"sig\":0,\"field_type\":{\"tp\":251,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABU=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABY=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABc=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}") + c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":2,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAQ=\",\"sig\":0,\"field_type\":{\"tp\":4,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAU=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAY=\",\"sig\":0,\"field_type\":{\"tp\":6,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAc=\",\"sig\":0,\"field_type\":{\"tp\":7,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAg=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAk=\",\"sig\":0,\"field_type\":{\"tp\":9,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAo=\",\"sig\":0,\"field_type\":{\"tp\":10,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAs=\",\"sig\":0,\"field_type\":{\"tp\":11,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAw=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAA0=\",\"sig\":0,\"field_type\":{\"tp\":13,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAA8=\",\"sig\":0,\"field_type\":{\"tp\":15,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABA=\",\"sig\":0,\"field_type\":{\"tp\":245,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABE=\",\"sig\":0,\"field_type\":{\"tp\":246,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABI=\",\"sig\":0,\"field_type\":{\"tp\":249,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABM=\",\"sig\":0,\"field_type\":{\"tp\":250,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABQ=\",\"sig\":0,\"field_type\":{\"tp\":251,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABU=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABY=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAABc=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}") pbExprs = ExpressionsToPBList(sc, colExprs, client) jsons := []string{ - "{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":2,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAQ=\",\"sig\":0,\"field_type\":{\"tp\":4,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAU=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAY=\",\"sig\":0,\"field_type\":{\"tp\":6,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAc=\",\"sig\":0,\"field_type\":{\"tp\":7,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAg=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAk=\",\"sig\":0,\"field_type\":{\"tp\":9,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAo=\",\"sig\":0,\"field_type\":{\"tp\":10,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAs=\",\"sig\":0,\"field_type\":{\"tp\":11,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAAw=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAA0=\",\"sig\":0,\"field_type\":{\"tp\":13,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAAA8=\",\"sig\":0,\"field_type\":{\"tp\":15,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABA=\",\"sig\":0,\"field_type\":{\"tp\":245,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABE=\",\"sig\":0,\"field_type\":{\"tp\":246,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABI=\",\"sig\":0,\"field_type\":{\"tp\":249,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABM=\",\"sig\":0,\"field_type\":{\"tp\":250,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABQ=\",\"sig\":0,\"field_type\":{\"tp\":251,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABU=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABY=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":201,\"val\":\"gAAAAAAAABc=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":2,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAQ=\",\"sig\":0,\"field_type\":{\"tp\":4,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAU=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAY=\",\"sig\":0,\"field_type\":{\"tp\":6,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAc=\",\"sig\":0,\"field_type\":{\"tp\":7,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAg=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAk=\",\"sig\":0,\"field_type\":{\"tp\":9,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAo=\",\"sig\":0,\"field_type\":{\"tp\":10,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAs=\",\"sig\":0,\"field_type\":{\"tp\":11,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAAw=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAA0=\",\"sig\":0,\"field_type\":{\"tp\":13,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAAA8=\",\"sig\":0,\"field_type\":{\"tp\":15,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABA=\",\"sig\":0,\"field_type\":{\"tp\":245,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABE=\",\"sig\":0,\"field_type\":{\"tp\":246,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABI=\",\"sig\":0,\"field_type\":{\"tp\":249,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABM=\",\"sig\":0,\"field_type\":{\"tp\":250,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABQ=\",\"sig\":0,\"field_type\":{\"tp\":251,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABU=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABY=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":201,\"val\":\"gAAAAAAAABc=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", } for i, pbExpr := range pbExprs { c.Assert(pbExprs, NotNil) @@ -214,7 +214,7 @@ func (s *testEvaluatorSuite) TestColumn2Pb(c *C) { c.Assert(pbExpr, NotNil) js, err = json.Marshal(pbExpr) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":2,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":4,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":6,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":7,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":9,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":10,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":11,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":13,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":15,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":245,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":246,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":249,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":250,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":251,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}") + c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":2,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":4,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":6,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":7,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":9,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":10,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":11,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":13,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":15,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":245,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":246,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":249,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":250,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":251,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}") c.Assert(len(pushed), Equals, len(colExprs)) c.Assert(len(remained), Equals, 0) } @@ -238,18 +238,18 @@ func (s *testEvaluatorSuite) TestCompareFunc2Pb(c *C) { c.Assert(len(remained), Equals, 0) js, err := json.Marshal(pbExpr) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":100,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":110,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":120,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":130,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":140,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":150,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":160,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}") + c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":100,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":110,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":120,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":130,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":140,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":150,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}},{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":160,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}") pbExprs := ExpressionsToPBList(sc, compareExprs, client) c.Assert(len(pbExprs), Equals, len(compareExprs)) jsons := []string{ - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":100,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":110,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":120,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":130,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":140,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":150,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":160,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":100,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":110,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":120,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":130,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":140,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":150,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":8,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":160,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", } for i, pbExpr := range pbExprs { c.Assert(pbExprs, NotNil) @@ -310,10 +310,10 @@ func (s *testEvaluatorSuite) TestArithmeticalFunc2Pb(c *C) { } jsons := make(map[string]string) - jsons[ast.Plus] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":200,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"binary\"}}" - jsons[ast.Minus] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":204,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"binary\"}}" - jsons[ast.Mul] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":208,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"binary\"}}" - jsons[ast.Div] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":211,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":23,\"decimal\":31,\"collate\":63,\"charset\":\"binary\"}}" + jsons[ast.Plus] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":200,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"binary\"}}" + jsons[ast.Minus] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":204,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"binary\"}}" + jsons[ast.Mul] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":208,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"binary\"}}" + jsons[ast.Div] = "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":211,\"field_type\":{\"tp\":5,\"flag\":128,\"flen\":23,\"decimal\":31,\"collate\":63,\"charset\":\"binary\"}}" pbExprs := ExpressionsToPBList(sc, arithmeticalFuncs, client) for i, pbExpr := range pbExprs { @@ -345,7 +345,7 @@ func (s *testEvaluatorSuite) TestDateFunc2Pb(c *C) { c.Assert(pbExprs[0], NotNil) js, err := json.Marshal(pbExprs[0]) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":6001,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":0,\"decimal\":-1,\"collate\":83,\"charset\":\"utf8\"}}") + c.Assert(string(js), Equals, "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":6001,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":0,\"decimal\":-1,\"collate\":46,\"charset\":\"utf8mb4\"}}") } func (s *testEvaluatorSuite) TestLogicalFunc2Pb(c *C) { @@ -372,10 +372,10 @@ func (s *testEvaluatorSuite) TestLogicalFunc2Pb(c *C) { pbExprs := ExpressionsToPBList(sc, logicalFuncs, client) jsons := []string{ - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3102,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3101,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3102,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", "null", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3104,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":1,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3104,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", } for i, pbExpr := range pbExprs { js, err := json.Marshal(pbExpr) @@ -443,9 +443,9 @@ func (s *testEvaluatorSuite) TestControlFunc2Pb(c *C) { pbExprs := ExpressionsToPBList(sc, controlFuncs, client) jsons := []string{ - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":4208,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":0,\"decimal\":0,\"collate\":83,\"charset\":\"\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":4107,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":-1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", - "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":4101,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":-1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":4208,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":0,\"decimal\":0,\"collate\":46,\"charset\":\"\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAM=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":4107,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":-1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":4101,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":-1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", "null", } for i, pbExpr := range pbExprs { @@ -475,8 +475,8 @@ func (s *testEvaluatorSuite) TestOtherFunc2Pb(c *C) { pbExprs := ExpressionsToPBList(sc, otherFuncs, client) jsons := map[string]string{ - ast.Coalesce: "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":4201,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":0,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}", - ast.IsNull: "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":3116,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", + ast.Coalesce: "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":4201,\"field_type\":{\"tp\":3,\"flag\":128,\"flen\":0,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}", + ast.IsNull: "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":3,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}}],\"sig\":3116,\"field_type\":{\"tp\":8,\"flag\":128,\"flen\":1,\"decimal\":0,\"collate\":63,\"charset\":\"binary\"}}", } for i, pbExpr := range pbExprs { js, err := json.Marshal(pbExpr) @@ -493,13 +493,13 @@ func (s *testEvaluatorSuite) TestGroupByItem2Pb(c *C) { pbByItem := GroupByItemToPB(sc, client, item) js, err := json.Marshal(pbByItem) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},\"desc\":false}") + c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},\"desc\":false}") item = dg.genColumn(mysql.TypeDouble, 1) pbByItem = GroupByItemToPB(sc, client, item) js, err = json.Marshal(pbByItem) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},\"desc\":false}") + c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},\"desc\":false}") } func (s *testEvaluatorSuite) TestSortByItem2Pb(c *C) { @@ -510,17 +510,17 @@ func (s *testEvaluatorSuite) TestSortByItem2Pb(c *C) { pbByItem := SortByItemToPB(sc, client, item, false) js, err := json.Marshal(pbByItem) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},\"desc\":false}") + c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAA=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},\"desc\":false}") item = dg.genColumn(mysql.TypeDouble, 1) pbByItem = SortByItemToPB(sc, client, item, false) js, err = json.Marshal(pbByItem) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},\"desc\":false}") + c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},\"desc\":false}") item = dg.genColumn(mysql.TypeDouble, 1) pbByItem = SortByItemToPB(sc, client, item, true) js, err = json.Marshal(pbByItem) c.Assert(err, IsNil) - c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}},\"desc\":true}") + c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"}},\"desc\":true}") } diff --git a/expression/typeinfer_test.go b/expression/typeinfer_test.go index bb86b140d5caf..ba3a616167185 100644 --- a/expression/typeinfer_test.go +++ b/expression/typeinfer_test.go @@ -163,7 +163,7 @@ func (s *testInferTypeSuite) createTestCase4Constants() []typeInferTestCase { {"NULL", mysql.TypeNull, charset.CharsetBin, mysql.BinaryFlag, 0, 0}, {"TRUE", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.IsBooleanFlag, 1, 0}, {"FALSE", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.IsBooleanFlag, 1, 0}, - {"'1234'", mysql.TypeVarString, charset.CharsetUTF8, 0, 4, types.UnspecifiedLength}, + {"'1234'", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 4, types.UnspecifiedLength}, {"_utf8'1234'", mysql.TypeVarString, charset.CharsetUTF8, 0, 4, types.UnspecifiedLength}, {"_binary'1234'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 4, types.UnspecifiedLength}, {"b'0001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 1, 0}, @@ -179,14 +179,14 @@ func (s *testInferTypeSuite) createTestCase4Cast() []typeInferTestCase { return []typeInferTestCase{ {"CAST(c_int_d AS BINARY)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, -1, -1}, // TODO: Flen should be 11. {"CAST(c_int_d AS BINARY(5))", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 5, -1}, - {"CAST(c_int_d AS CHAR)", mysql.TypeVarString, charset.CharsetUTF8, 0, -1, -1}, // TODO: Flen should be 11. - {"CAST(c_int_d AS CHAR(5))", mysql.TypeVarString, charset.CharsetUTF8, 0, 5, -1}, + {"CAST(c_int_d AS CHAR)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, -1, -1}, // TODO: Flen should be 11. + {"CAST(c_int_d AS CHAR(5))", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 5, -1}, {"CAST(c_int_d AS DATE)", mysql.TypeDate, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, {"CAST(c_int_d AS DATETIME)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0}, {"CAST(c_int_d AS DECIMAL)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, {"CAST(c_int_d AS DECIMAL(10))", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, {"CAST(c_int_d AS DECIMAL(10,3))", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 10, 3}, // TODO: Flen should be 12 - {"CAST(c_int_d AS JSON)", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag | mysql.ParseToJSONFlag, 12582912 / 3, 0}, + {"CAST(c_int_d AS JSON)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag | mysql.ParseToJSONFlag, 12582912 / 3, 0}, {"CAST(c_int_d AS SIGNED)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 22, 0}, // TODO: Flen should be 11. {"CAST(c_int_d AS SIGNED INTEGER)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 22, 0}, // TODO: Flen should be 11. {"CAST(c_int_d AS TIME)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, @@ -217,65 +217,65 @@ func (s *testInferTypeSuite) createTestCase4Columns() []typeInferTestCase { {"c_time_d ", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, {"c_timestamp ", mysql.TypeTimestamp, charset.CharsetBin, mysql.BinaryFlag, 24, 4}, {"c_timestamp_d", mysql.TypeTimestamp, charset.CharsetBin, mysql.BinaryFlag, 19, 0}, - {"c_char ", mysql.TypeString, charset.CharsetUTF8, 0, 20, 0}, // TODO: flag should be BinaryFlag - {"c_bchar ", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 20, 0}, - {"c_varchar ", mysql.TypeVarchar, charset.CharsetUTF8, 0, 20, 0}, // TODO: BinaryFlag, tp should be TypeVarString - {"c_bvarchar ", mysql.TypeVarchar, charset.CharsetUTF8, mysql.BinaryFlag, 20, 0}, // TODO: BinaryFlag, tp should be TypeVarString - {"c_text_d ", mysql.TypeBlob, charset.CharsetUTF8, 0, 65535, 0}, // TODO: BlobFlag, BinaryFlag - {"c_btext_d ", mysql.TypeBlob, charset.CharsetUTF8, mysql.BinaryFlag, 65535, 0}, // TODO: BlobFlag, BinaryFlag - {"c_binary ", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, // TODO: BinaryFlag - {"c_varbinary ", mysql.TypeVarchar, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, // TODO: BinaryFlag, tp should be TypeVarString - {"c_blob_d ", mysql.TypeBlob, charset.CharsetBin, mysql.BinaryFlag, 65535, 0}, // TODO: BlobFlag, BinaryFlag - {"c_set ", mysql.TypeSet, charset.CharsetUTF8, 0, types.UnspecifiedLength, 0}, // TODO: SetFlag, BinaryFlag, Flen should be 5 - {"c_enum ", mysql.TypeEnum, charset.CharsetUTF8, 0, types.UnspecifiedLength, 0}, // TODO: EnumFlag, BinaryFlag, Flen should be 1 + {"c_char ", mysql.TypeString, charset.CharsetUTF8MB4, 0, 20, 0}, // TODO: flag should be BinaryFlag + {"c_bchar ", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, 0}, + {"c_varchar ", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 20, 0}, // TODO: BinaryFlag, tp should be TypeVarString + {"c_bvarchar ", mysql.TypeVarchar, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, 0}, // TODO: BinaryFlag, tp should be TypeVarString + {"c_text_d ", mysql.TypeBlob, charset.CharsetUTF8MB4, 0, 65535, 0}, // TODO: BlobFlag, BinaryFlag + {"c_btext_d ", mysql.TypeBlob, charset.CharsetUTF8MB4, mysql.BinaryFlag, 65535, 0}, // TODO: BlobFlag, BinaryFlag + {"c_binary ", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, // TODO: BinaryFlag + {"c_varbinary ", mysql.TypeVarchar, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, // TODO: BinaryFlag, tp should be TypeVarString + {"c_blob_d ", mysql.TypeBlob, charset.CharsetBin, mysql.BinaryFlag, 65535, 0}, // TODO: BlobFlag, BinaryFlag + {"c_set ", mysql.TypeSet, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, 0}, // TODO: SetFlag, BinaryFlag, Flen should be 5 + {"c_enum ", mysql.TypeEnum, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, 0}, // TODO: EnumFlag, BinaryFlag, Flen should be 1 } } func (s *testInferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase { return []typeInferTestCase{ {"strcmp(c_char, c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 2, 0}, - {"space(c_int_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"space(c_int_d)", mysql.TypeLongBlob, mysql.DefaultCharset, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"CONCAT(c_binary, c_int_d)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 40, types.UnspecifiedLength}, - {"CONCAT(c_bchar, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, mysql.BinaryFlag, 40, types.UnspecifiedLength}, - {"CONCAT('T', 'i', 'DB')", mysql.TypeVarString, charset.CharsetUTF8, 0, 4, types.UnspecifiedLength}, + {"CONCAT(c_bchar, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 40, types.UnspecifiedLength}, + {"CONCAT('T', 'i', 'DB')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 4, types.UnspecifiedLength}, {"CONCAT('T', 'i', 'DB', c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 24, types.UnspecifiedLength}, - {"CONCAT_WS('-', 'T', 'i', 'DB')", mysql.TypeVarString, charset.CharsetUTF8, 0, 6, types.UnspecifiedLength}, + {"CONCAT_WS('-', 'T', 'i', 'DB')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 6, types.UnspecifiedLength}, {"CONCAT_WS(',', 'TiDB', c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 25, types.UnspecifiedLength}, - {"left(c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"right(c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"lower(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"left(c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"right(c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"lower(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"lower(c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"upper(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"upper(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"upper(c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"replace(1234, 2, 55)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"replace(1234, 2, 55)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"replace(c_binary, 1, 2)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"to_base64(c_binary)", mysql.TypeVarString, charset.CharsetUTF8, 0, 28, types.UnspecifiedLength}, - {"substr(c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"to_base64(c_binary)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 28, types.UnspecifiedLength}, + {"substr(c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"substr(c_binary, c_int_d)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"uuid()", mysql.TypeVarString, charset.CharsetUTF8, 0, 36, types.UnspecifiedLength}, + {"uuid()", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 36, types.UnspecifiedLength}, {"bit_length(c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, - {"substring_index(c_int_d, '.', 1)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"substring_index(c_int_d, '.', 1)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"substring_index(c_binary, '.', 1)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"hex(c_char)", mysql.TypeVarString, charset.CharsetUTF8, 0, 120, types.UnspecifiedLength}, - {"hex(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 22, types.UnspecifiedLength}, + {"hex(c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 120, types.UnspecifiedLength}, + {"hex(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 22, types.UnspecifiedLength}, {"unhex(c_int_d)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 6, types.UnspecifiedLength}, {"unhex(c_char)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 30, types.UnspecifiedLength}, - {"ltrim(c_char)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"ltrim(c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"ltrim(c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"rtrim(c_char)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"rtrim(c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"rtrim(c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"trim(c_char)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"trim(c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"trim(c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"ascii(c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, {"ord(c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, {`c_int_d like 'abc%'`, mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 1, 0}, - {"tidb_version()", mysql.TypeVarString, charset.CharsetUTF8, 0, len(printer.GetTiDBInfo()), types.UnspecifiedLength}, + {"tidb_version()", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, len(printer.GetTiDBInfo()), types.UnspecifiedLength}, {"tidb_is_ddl_owner()", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, - {"password(c_char)", mysql.TypeVarString, charset.CharsetUTF8, 0, mysql.PWDHashLen + 1, types.UnspecifiedLength}, - {"elt(c_int_d, c_char, c_char, c_char)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, + {"password(c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, mysql.PWDHashLen + 1, types.UnspecifiedLength}, + {"elt(c_int_d, c_char, c_char, c_char)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, {"elt(c_int_d, c_char, c_char, c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"elt(c_int_d, c_char, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"elt(c_int_d, c_char, c_double_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 22, types.UnspecifiedLength}, + {"elt(c_int_d, c_char, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"elt(c_int_d, c_char, c_double_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 22, types.UnspecifiedLength}, {"elt(c_int_d, c_char, c_double_d, c_int_d, c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 22, types.UnspecifiedLength}, {"locate(c_char, c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, @@ -287,14 +287,14 @@ func (s *testInferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase { {"locate(c_binary, c_char, c_int_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, {"locate(c_binary, c_binary, c_int_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, - {"lpad('TiDB', 12, 'go' )", mysql.TypeVarString, charset.CharsetUTF8, 0, 48, types.UnspecifiedLength}, + {"lpad('TiDB', 12, 'go' )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 48, types.UnspecifiedLength}, {"lpad(c_binary, 12, 'go' )", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 12, types.UnspecifiedLength}, {"lpad(c_char, c_int_d, c_binary)", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"lpad(c_char, c_int_d, c_char )", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"rpad('TiDB', 12, 'go' )", mysql.TypeVarString, charset.CharsetUTF8, 0, 48, types.UnspecifiedLength}, + {"lpad(c_char, c_int_d, c_char )", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"rpad('TiDB', 12, 'go' )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 48, types.UnspecifiedLength}, {"rpad(c_binary, 12, 'go' )", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 12, types.UnspecifiedLength}, {"rpad(c_char, c_int_d, c_binary)", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"rpad(c_char, c_int_d, c_char )", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"rpad(c_char, c_int_d, c_char )", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"from_base64(c_int_d )", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"from_base64(c_bigint_d )", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, @@ -313,22 +313,22 @@ func (s *testInferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase { {"from_base64(c_set )", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"from_base64(c_enum )", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"bin(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"bin(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, + {"bin(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"bin(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, {"char_length(c_int_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, {"char_length(c_float_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, @@ -399,36 +399,36 @@ func (s *testInferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase { {"instr(c_char, c_char )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, {"instr(c_char, c_time_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, - {"reverse(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"reverse(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"reverse(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 12, types.UnspecifiedLength}, - {"reverse(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 22, types.UnspecifiedLength}, - {"reverse(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 8, types.UnspecifiedLength}, - {"reverse(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"reverse(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"reverse(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 65535, types.UnspecifiedLength}, + {"reverse(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"reverse(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"reverse(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 12, types.UnspecifiedLength}, + {"reverse(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 22, types.UnspecifiedLength}, + {"reverse(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 8, types.UnspecifiedLength}, + {"reverse(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"reverse(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"reverse(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 65535, types.UnspecifiedLength}, {"reverse(c_binary )", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"reverse(c_varbinary )", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"reverse(c_blob_d )", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 65535, types.UnspecifiedLength}, - {"reverse(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, types.UnspecifiedLength, types.UnspecifiedLength}, - {"reverse(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, types.UnspecifiedLength, types.UnspecifiedLength}, - - {"oct(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"oct(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, + {"reverse(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, types.UnspecifiedLength}, + {"reverse(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, types.UnspecifiedLength}, + + {"oct(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"oct(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, {"find_in_set(c_int_d , c_text_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, {"find_in_set(c_bigint_d , c_text_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, @@ -447,30 +447,30 @@ func (s *testInferTypeSuite) createTestCase4StrFuncs() []typeInferTestCase { {"find_in_set(c_set , c_text_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, {"find_in_set(c_enum , c_text_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, - {"make_set(c_int_d , c_text_d)", mysql.TypeVarString, charset.CharsetUTF8, mysql.BinaryFlag, 65535, types.UnspecifiedLength}, + {"make_set(c_int_d , c_text_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 65535, types.UnspecifiedLength}, {"make_set(c_bigint_d , c_text_d, c_binary)", mysql.TypeMediumBlob, charset.CharsetBin, mysql.BinaryFlag, 65556, types.UnspecifiedLength}, - {"quote(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 42, types.UnspecifiedLength}, - {"quote(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 42, types.UnspecifiedLength}, - {"quote(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"quote(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 46, types.UnspecifiedLength}, + {"quote(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 42, types.UnspecifiedLength}, + {"quote(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 42, types.UnspecifiedLength}, + {"quote(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"quote(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 46, types.UnspecifiedLength}, - {"convert(c_double_d using c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"convert(c_binary using c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"convert(c_binary using c_binary)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"convert(c_text_d using c_binary)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"convert(c_double_d using c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"convert(c_binary using c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"convert(c_binary using c_binary)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"convert(c_text_d using c_binary)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"insert(c_varchar, c_int_d, c_int_d, c_varchar)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"insert(c_varchar, c_int_d, c_int_d, c_varchar)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"insert(c_varchar, c_int_d, c_int_d, c_binary)", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"insert(c_binary, c_int_d, c_int_d, c_varchar)", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"insert(c_binary, c_int_d, c_int_d, c_binary)", mysql.TypeLongBlob, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"export_set(c_double_d, c_text_d, c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"export_set(c_double_d, c_text_d, c_text_d, c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"export_set(c_double_d, c_text_d, c_text_d, c_text_d, c_int_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"export_set(c_double_d, c_text_d, c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"export_set(c_double_d, c_text_d, c_text_d, c_text_d)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"export_set(c_double_d, c_text_d, c_text_d, c_text_d, c_int_d)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"format(c_double_d, c_double_d)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, - {"format(c_double_d, c_double_d, c_binary)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"format(c_double_d, c_double_d)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, + {"format(c_double_d, c_double_d, c_binary)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, types.UnspecifiedLength}, {"field(c_double_d, c_text_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, } @@ -563,8 +563,8 @@ func (s *testInferTypeSuite) createTestCase4MathFuncs() []typeInferTestCase { {"ceiling(18446744073709551615)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, {"ceiling(18446744073709551615.1)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 22, 0}, - {"conv(c_char, c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"conv(c_int_d, c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, + {"conv(c_char, c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"conv(c_int_d, c_int_d, c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, {"abs(c_int_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, {"abs(c_bigint_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, @@ -790,24 +790,24 @@ func (s *testInferTypeSuite) createTestCase4ControlFuncs() []typeInferTestCase { return []typeInferTestCase{ {"ifnull(c_int_d, c_int_d)", mysql.TypeLong, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, {"ifnull(c_int_d, c_decimal)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 14, 3}, - {"ifnull(c_int_d, c_char)", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 20, types.UnspecifiedLength}, + {"ifnull(c_int_d, c_char)", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"ifnull(c_int_d, c_binary)", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"ifnull(c_char, c_binary)", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"ifnull(null, null)", mysql.TypeNull, charset.CharsetBin, mysql.BinaryFlag, 0, 0}, - {"ifnull(c_double_d, c_timestamp_d)", mysql.TypeVarchar, charset.CharsetUTF8, 0, 22, types.UnspecifiedLength}, - {"ifnull(c_json, c_decimal)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, math.MaxUint32, types.UnspecifiedLength}, + {"ifnull(c_double_d, c_timestamp_d)", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 22, types.UnspecifiedLength}, + {"ifnull(c_json, c_decimal)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, math.MaxUint32, types.UnspecifiedLength}, {"if(c_int_d, c_decimal, c_int_d)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 14, 3}, - {"if(c_int_d, c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 20, types.UnspecifiedLength}, + {"if(c_int_d, c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"if(c_int_d, c_binary, c_int_d)", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"if(c_int_d, c_bchar, c_int_d)", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"if(c_int_d, c_char, c_decimal)", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"if(c_int_d, c_datetime, c_int_d)", mysql.TypeVarchar, charset.CharsetUTF8, 0, 22, types.UnspecifiedLength}, + {"if(c_int_d, c_bchar, c_int_d)", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, types.UnspecifiedLength}, + {"if(c_int_d, c_char, c_decimal)", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, types.UnspecifiedLength}, + {"if(c_int_d, c_datetime, c_int_d)", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 22, types.UnspecifiedLength}, {"if(c_int_d, c_int_d, c_double_d)", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, 22, types.UnspecifiedLength}, - {"if(c_int_d, c_time_d, c_datetime)", mysql.TypeDatetime, charset.CharsetUTF8, mysql.BinaryFlag, 22, 2}, // TODO: should not be BinaryFlag - {"if(c_int_d, c_time, c_json)", mysql.TypeLongBlob, charset.CharsetUTF8, 0, math.MaxUint32, types.UnspecifiedLength}, + {"if(c_int_d, c_time_d, c_datetime)", mysql.TypeDatetime, charset.CharsetUTF8MB4, mysql.BinaryFlag, 22, 2}, // TODO: should not be BinaryFlag + {"if(c_int_d, c_time, c_json)", mysql.TypeLongBlob, charset.CharsetUTF8MB4, 0, math.MaxUint32, types.UnspecifiedLength}, {"if(null, null, null)", mysql.TypeNull, charset.CharsetBin, mysql.BinaryFlag, 0, 0}, - {"case when c_int_d then c_char else c_varchar end", mysql.TypeVarchar, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"case when c_int_d > 1 then c_double_d else c_bchar end", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 22, types.UnspecifiedLength}, + {"case when c_int_d then c_char else c_varchar end", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"case when c_int_d > 1 then c_double_d else c_bchar end", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 22, types.UnspecifiedLength}, {"case when c_int_d > 2 then c_double_d when c_int_d < 1 then c_decimal else c_double_d end", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, 22, 3}, {"case when c_double_d > 2 then c_decimal else 1 end", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 6, 3}, {"case when null then null else null end", mysql.TypeNull, charset.CharsetBin, mysql.BinaryFlag, 0, types.UnspecifiedLength}, @@ -830,7 +830,7 @@ func (s *testInferTypeSuite) createTestCase4Aggregations() []typeInferTestCase { {"avg(1.0)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, 5}, {"avg(1.2e2)", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxRealWidth, types.UnspecifiedLength}, {"avg(c_char)", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxRealWidth, types.UnspecifiedLength}, - {"group_concat(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, mysql.MaxBlobWidth, 0}, + {"group_concat(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, mysql.MaxBlobWidth, 0}, } } @@ -839,110 +839,110 @@ func (s *testInferTypeSuite) createTestCase4InfoFunc() []typeInferTestCase { {"last_insert_id( )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, mysql.MaxIntWidth, 0}, {"last_insert_id(c_int_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, mysql.MaxIntWidth, 0}, {"found_rows()", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, mysql.MaxIntWidth, 0}, - {"database()", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"current_user()", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, - {"user()", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, + {"database()", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"current_user()", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, + {"user()", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, {"connection_id()", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, mysql.MaxIntWidth, 0}, - {"version()", mysql.TypeVarString, charset.CharsetUTF8, 0, 64, types.UnspecifiedLength}, + {"version()", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 64, types.UnspecifiedLength}, } } func (s *testInferTypeSuite) createTestCase4EncryptionFuncs() []typeInferTestCase { return []typeInferTestCase{ - {"md5(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5('1234' )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - {"md5(1234 )", mysql.TypeVarString, charset.CharsetUTF8, 0, 32, types.UnspecifiedLength}, - - {"sha(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha('1234' )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha(1234 )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - - {"sha1(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1('1234' )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - {"sha1(1234 )", mysql.TypeVarString, charset.CharsetUTF8, 0, 40, types.UnspecifiedLength}, - - {"sha2(c_int_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_bigint_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_float_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_double_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_decimal , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_datetime , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_time_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_timestamp_d, 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_char , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_varchar , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_text_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_binary , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_varbinary , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_blob_d , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_set , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_enum , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2('1234' , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(1234 , 0)", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - - {"sha2(c_int_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_bigint_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_float_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_double_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_decimal , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_datetime , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_time_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_timestamp_d, '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_char , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_varchar , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_text_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_binary , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_varbinary , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_blob_d , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_set , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(c_enum , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2('1234' , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, - {"sha2(1234 , '256')", mysql.TypeVarString, charset.CharsetUTF8, 0, 128, types.UnspecifiedLength}, + {"md5(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5('1234' )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + {"md5(1234 )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 32, types.UnspecifiedLength}, + + {"sha(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha('1234' )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha(1234 )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + + {"sha1(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1('1234' )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + {"sha1(1234 )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 40, types.UnspecifiedLength}, + + {"sha2(c_int_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_bigint_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_float_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_double_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_decimal , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_datetime , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_time_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_timestamp_d, 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_char , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_varchar , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_text_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_binary , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_varbinary , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_blob_d , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_set , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_enum , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2('1234' , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(1234 , 0)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + + {"sha2(c_int_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_bigint_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_float_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_double_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_decimal , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_datetime , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_time_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_timestamp_d, '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_char , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_varchar , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_text_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_binary , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_varbinary , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_blob_d , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_set , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(c_enum , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2('1234' , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, + {"sha2(1234 , '256')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 128, types.UnspecifiedLength}, {"AES_ENCRYPT(c_int_d, 'key')", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 32, types.UnspecifiedLength}, {"AES_ENCRYPT(c_char, 'key')", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 32, types.UnspecifiedLength}, @@ -985,7 +985,7 @@ func (s *testInferTypeSuite) createTestCase4CompareFuncs() []typeInferTestCase { {"coalesce(c_int_d, 1)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, {"coalesce(NULL, c_int_d)", mysql.TypeLong, charset.CharsetBin, mysql.BinaryFlag, 11, 0}, {"coalesce(c_int_d, c_decimal)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, - {"coalesce(c_int_d, c_datetime)", mysql.TypeVarString, charset.CharsetUTF8, 0, 22, types.UnspecifiedLength}, + {"coalesce(c_int_d, c_datetime)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 22, types.UnspecifiedLength}, {"isnull(c_int_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 1, 0}, {"isnull(c_bigint_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 1, 0}, @@ -1012,9 +1012,9 @@ func (s *testInferTypeSuite) createTestCase4CompareFuncs() []typeInferTestCase { {"nullif(c_datetime , 123)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, 2}, // TODO: tp should be TypeVarString, no binary flag {"nullif(c_time_d , 123)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, // TODO: tp should be TypeVarString, no binary flag {"nullif(c_timestamp_d, 123)", mysql.TypeTimestamp, charset.CharsetBin, mysql.BinaryFlag, 19, 0}, // TODO: tp should be TypeVarString, no binary flag - {"nullif(c_char , 123)", mysql.TypeString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"nullif(c_varchar , 123)", mysql.TypeVarchar, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, // TODO: tp should be TypeVarString - {"nullif(c_text_d , 123)", mysql.TypeBlob, charset.CharsetUTF8, 0, 65535, types.UnspecifiedLength}, // TODO: tp should be TypeMediumBlob + {"nullif(c_char , 123)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"nullif(c_varchar , 123)", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, // TODO: tp should be TypeVarString + {"nullif(c_text_d , 123)", mysql.TypeBlob, charset.CharsetUTF8MB4, 0, 65535, types.UnspecifiedLength}, // TODO: tp should be TypeMediumBlob {"nullif(c_binary , 123)", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, // TODO: tp should be TypeVarString {"nullif(c_varbinary , 123)", mysql.TypeVarchar, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, // TODO: tp should be TypeVarString {"nullif(c_blob_d , 123)", mysql.TypeBlob, charset.CharsetBin, mysql.BinaryFlag, 65535, types.UnspecifiedLength}, // TODO: tp should be TypeVarString @@ -1044,14 +1044,14 @@ func (s *testInferTypeSuite) createTestCase4Miscellaneous() []typeInferTestCase {"inet_aton(c_timestamp_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 21, 0}, {"inet_aton(c_binary)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 21, 0}, - {"inet_ntoa(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_float_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_double_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_decimal)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_datetime)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_time_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, - {"inet_ntoa(c_binary)", mysql.TypeVarString, charset.CharsetUTF8, 0, 93, 0}, + {"inet_ntoa(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_float_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_double_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_decimal)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_datetime)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_time_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, + {"inet_ntoa(c_binary)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 93, 0}, {"inet6_aton(c_int_d)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 16, 0}, {"inet6_aton(c_float_d)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 16, 0}, @@ -1062,14 +1062,14 @@ func (s *testInferTypeSuite) createTestCase4Miscellaneous() []typeInferTestCase {"inet6_aton(c_timestamp_d)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 16, 0}, {"inet6_aton(c_binary)", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 16, 0}, - {"inet6_ntoa(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_float_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_double_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_decimal)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_datetime)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_time_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, - {"inet6_ntoa(c_binary)", mysql.TypeVarString, charset.CharsetUTF8, 0, 117, 0}, + {"inet6_ntoa(c_int_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_float_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_double_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_decimal)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_datetime)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_time_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, + {"inet6_ntoa(c_binary)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 117, 0}, {"is_ipv4(c_int_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 1, 0}, {"is_ipv4(c_float_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 1, 0}, @@ -1112,18 +1112,18 @@ func (s *testInferTypeSuite) createTestCase4Miscellaneous() []typeInferTestCase {"any_value(c_float_d)", mysql.TypeFloat, charset.CharsetBin, mysql.BinaryFlag, 12, types.UnspecifiedLength}, {"any_value(c_double_d)", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, 22, types.UnspecifiedLength}, {"any_value(c_decimal)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 6, 3}, // TODO: Flen should be 8. - {"any_value(c_datetime)", mysql.TypeDatetime, charset.CharsetUTF8, 0, 22, 2}, + {"any_value(c_datetime)", mysql.TypeDatetime, charset.CharsetUTF8MB4, 0, 22, 2}, {"any_value(c_time_d)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 10, 0}, - {"any_value(c_timestamp_d)", mysql.TypeTimestamp, charset.CharsetUTF8, 0, 19, 0}, - {"any_value(c_char)", mysql.TypeString, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"any_value(c_bchar)", mysql.TypeString, charset.CharsetUTF8, mysql.BinaryFlag, 20, types.UnspecifiedLength}, - {"any_value(c_varchar)", mysql.TypeVarchar, charset.CharsetUTF8, 0, 20, types.UnspecifiedLength}, - {"any_value(c_text_d)", mysql.TypeBlob, charset.CharsetUTF8, 0, 65535, types.UnspecifiedLength}, + {"any_value(c_timestamp_d)", mysql.TypeTimestamp, charset.CharsetUTF8MB4, 0, 19, 0}, + {"any_value(c_char)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"any_value(c_bchar)", mysql.TypeString, charset.CharsetUTF8MB4, mysql.BinaryFlag, 20, types.UnspecifiedLength}, + {"any_value(c_varchar)", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, + {"any_value(c_text_d)", mysql.TypeBlob, charset.CharsetUTF8MB4, 0, 65535, types.UnspecifiedLength}, {"any_value(c_binary)", mysql.TypeString, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"any_value(c_varbinary)", mysql.TypeVarchar, charset.CharsetBin, mysql.BinaryFlag, 20, types.UnspecifiedLength}, {"any_value(c_blob_d)", mysql.TypeBlob, charset.CharsetBin, mysql.BinaryFlag, 65535, types.UnspecifiedLength}, - {"any_value(c_set)", mysql.TypeSet, charset.CharsetUTF8, 0, types.UnspecifiedLength, types.UnspecifiedLength}, - {"any_value(c_enum)", mysql.TypeEnum, charset.CharsetUTF8, 0, types.UnspecifiedLength, types.UnspecifiedLength}, + {"any_value(c_set)", mysql.TypeSet, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, types.UnspecifiedLength}, + {"any_value(c_enum)", mysql.TypeEnum, charset.CharsetUTF8MB4, 0, types.UnspecifiedLength, types.UnspecifiedLength}, } } @@ -1181,28 +1181,28 @@ func (s *testInferTypeSuite) createTestCase4OtherFuncs() []typeInferTestCase { {"bit_count(c_set )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 2, 0}, {"bit_count(c_enum )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 2, 0}, - {`@varname`, mysql.TypeVarString, charset.CharsetUTF8, 0, mysql.MaxFieldVarCharLength, types.UnspecifiedFsp}, + {`@varname`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, mysql.MaxFieldVarCharLength, types.UnspecifiedFsp}, } } func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { return []typeInferTestCase{ - {`time_format('150:02:28', '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - {`time_format(123456, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - {`time_format('bad string', '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - {`time_format(null, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - - {`date_format(null, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - {`date_format('2017-06-15', '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - {`date_format(151113102019.12, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8, 0, 44, types.UnspecifiedLength}, - - {"timestampadd(HOUR, c_int_d, c_timestamp_d)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, - {"timestampadd(minute, c_double_d, c_timestamp_d)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, - {"timestampadd(SeconD, c_int_d, c_char)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, - {"timestampadd(SeconD, c_varchar, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, - {"timestampadd(SeconD, c_int_d, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, - {"timestampadd(SeconD, c_double_d, c_bchar)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, - {"timestampadd(SeconD, c_int_d, c_blob_d)", mysql.TypeString, charset.CharsetUTF8, 0, 19, types.UnspecifiedLength}, + {`time_format('150:02:28', '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + {`time_format(123456, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + {`time_format('bad string', '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + {`time_format(null, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + + {`date_format(null, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + {`date_format('2017-06-15', '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + {`date_format(151113102019.12, '%r%r%r%r')`, mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 44, types.UnspecifiedLength}, + + {"timestampadd(HOUR, c_int_d, c_timestamp_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, + {"timestampadd(minute, c_double_d, c_timestamp_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, + {"timestampadd(SeconD, c_int_d, c_char)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, + {"timestampadd(SeconD, c_varchar, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, + {"timestampadd(SeconD, c_int_d, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, + {"timestampadd(SeconD, c_double_d, c_bchar)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, + {"timestampadd(SeconD, c_int_d, c_blob_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 19, types.UnspecifiedLength}, {"to_seconds(c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, {"to_days(c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, @@ -1237,33 +1237,33 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { {"timestampdiff(second, c_int_d, c_bchar)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, {"timestampdiff(YEAR, c_blob_d, c_bigint_d)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 20, 0}, - {"addtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, + {"addtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, {"addtime(c_datetime_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"addtime(c_datetime, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 2}, {"addtime(c_timestamp, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 4}, {"addtime(c_timestamp_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"addtime(c_time, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, {"addtime(c_time_d, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, - {"addtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - - {"subtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, + {"addtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + + {"subtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, {"subtime(c_datetime_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"subtime(c_datetime, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 2}, {"subtime(c_timestamp, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 4}, {"subtime(c_timestamp_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"subtime(c_time, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, {"subtime(c_time_d, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, - {"subtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, + {"subtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, {"timestamp(c_int_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0}, {"timestamp(c_float_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6}, @@ -1291,33 +1291,33 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { {"timestamp(c_timestamp, c_char)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6}, {"timestamp(c_int_d, c_datetime)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, 2}, - {"addtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, + {"addtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, {"addtime(c_datetime_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"addtime(c_datetime, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 2}, {"addtime(c_timestamp, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 4}, {"addtime(c_timestamp_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"addtime(c_time, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, {"addtime(c_time_d, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, - {"addtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"addtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - - {"subtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, + {"addtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"addtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + + {"subtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, {"subtime(c_datetime_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"subtime(c_datetime, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 2}, {"subtime(c_timestamp, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 4}, {"subtime(c_timestamp_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, {"subtime(c_time, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, {"subtime(c_time_d, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, - {"subtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, - {"subtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8, 0, 26, types.UnspecifiedLength}, + {"subtime(c_char, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_char, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_char, c_int_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_date, c_datetime)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, + {"subtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength}, {"hour(c_int_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, {"hour(c_bigint_d )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 3, 0}, @@ -1624,39 +1624,39 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { {"month(c_set )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 2, 0}, {"month(c_enum )", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, 2, 0}, - {"monthName(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"monthName(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - - {"dayName(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_char )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_binary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_set )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, - {"dayName(c_enum )", mysql.TypeVarString, charset.CharsetUTF8, 0, 10, types.UnspecifiedLength}, + {"monthName(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"monthName(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + + {"dayName(c_int_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_bigint_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_float_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_double_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_decimal )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_datetime )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_time_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_timestamp_d)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_char )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_varchar )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_text_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_binary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_varbinary )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_blob_d )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_set )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, + {"dayName(c_enum )", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 10, types.UnspecifiedLength}, {"now() ", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0}, {"now(0) ", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0}, @@ -1851,14 +1851,14 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { {"maketime(c_int_d, c_int_d, c_varchar)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 17, 6}, {"maketime(c_int_d, c_int_d, 1.2345)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 4}, - {"get_format(DATE, 'USA')", mysql.TypeVarString, charset.CharsetUTF8, 0, 17, types.UnspecifiedLength}, + {"get_format(DATE, 'USA')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 17, types.UnspecifiedLength}, {"convert_tz(c_time_d, c_text_d, c_text_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, types.MaxFsp}, {"from_unixtime(20170101.999)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, 3}, {"from_unixtime(20170101.1234567)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, types.MaxFsp}, {"from_unixtime('20170101.999')", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, types.MaxFsp}, - {"from_unixtime(20170101.123, '%H')", mysql.TypeVarString, charset.CharsetUTF8, 0, 2, types.UnspecifiedLength}, + {"from_unixtime(20170101.123, '%H')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 2, types.UnspecifiedLength}, {"extract(day from c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, {"extract(hour from c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, @@ -1917,17 +1917,17 @@ func (s *testInferTypeSuite) createTestCase4Literals() []typeInferTestCase { func (s *testInferTypeSuite) createTestCase4JSONFuncs() []typeInferTestCase { return []typeInferTestCase{ - {"json_type(c_json)", mysql.TypeVarString, charset.CharsetUTF8, 0, 51, types.UnspecifiedLength}, + {"json_type(c_json)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 51, types.UnspecifiedLength}, // TODO: Flen of json_unquote doesn't follow MySQL now. - {"json_unquote(c_json)", mysql.TypeVarString, charset.CharsetUTF8, 0, 0, types.UnspecifiedLength}, - {"json_extract(c_json, '')", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_set(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_insert(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_replace(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_remove(c_json, '')", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_merge(c_json, c_json)", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_object('k', 'v')", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, - {"json_array('k', 'v')", mysql.TypeJSON, charset.CharsetUTF8, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_unquote(c_json)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 0, types.UnspecifiedLength}, + {"json_extract(c_json, '')", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_set(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_insert(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_replace(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_remove(c_json, '')", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_merge(c_json, c_json)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_object('k', 'v')", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, + {"json_array('k', 'v')", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, } } diff --git a/infoschema/tables.go b/infoschema/tables.go index e1cd952fc9c7e..b2948ecf3fccf 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -82,8 +82,8 @@ func buildColumnInfo(tableName string, col columnInfo) *model.ColumnInfo { mCollation := charset.CharsetBin mFlag := mysql.UnsignedFlag if col.tp == mysql.TypeVarchar || col.tp == mysql.TypeBlob { - mCharset = mysql.DefaultCharset - mCollation = mysql.DefaultCollationName + mCharset = charset.CharsetUTF8MB4 + mCollation = charset.CollationUTF8MB4 mFlag = col.flag } fieldType := types.FieldType{ @@ -881,7 +881,7 @@ func dataForTables(ctx sessionctx.Context, schemas []*model.DBInfo) ([][]types.D for _, table := range schema.Tables { collation := table.Collate if collation == "" { - collation = charset.CollationUTF8 + collation = mysql.DefaultCollationName } createTime := types.Time{ Time: types.FromGoTime(table.GetUpdateTime()), diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 919f7b9a9e0b7..48d3f9956ccb9 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -168,11 +168,9 @@ func (s *testSuite) TestSchemataCharacterSet(c *C) { c.Assert(err, IsNil) defer do.Close() - // The default collation is still reported as utf8_bin - // But this is consistent with information_schema.tables -> table_collation tk := testkit.NewTestKit(c, store) tk.MustExec("CREATE DATABASE `foo` DEFAULT CHARACTER SET = 'utf8mb4'") tk.MustQuery("select default_character_set_name, default_collation_name FROM information_schema.SCHEMATA WHERE schema_name = 'foo'").Check( - testkit.Rows("utf8mb4 utf8_bin")) + testkit.Rows("utf8mb4 utf8mb4_bin")) } diff --git a/mysql/charset.go b/mysql/charset.go index 9cd96796efc71..f2e99a43765ef 100644 --- a/mysql/charset.go +++ b/mysql/charset.go @@ -551,13 +551,15 @@ var CollationNames = map[string]uint8{ // MySQL collation information. const ( - UTF8Charset = "utf8" - UTF8MB4Charset = "utf8mb4" - DefaultCharset = UTF8Charset - DefaultCollationID = 83 - BinaryCollationID = 63 - UTF8DefaultCollation = "utf8_bin" - DefaultCollationName = UTF8DefaultCollation + UTF8Charset = "utf8" + UTF8MB4Charset = "utf8mb4" + DefaultCharset = UTF8MB4Charset + // DefaultCollationID is utf8mb4_bin(46) + DefaultCollationID = 46 + BinaryCollationID = 63 + UTF8DefaultCollation = "utf8_bin" + UTF8MB4DefaultCollation = "utf8mb4_bin" + DefaultCollationName = UTF8MB4DefaultCollation // MaxBytesOfCharacter, is the max bytes length of a character, // refer to RFC3629, in UTF-8, characters from the U+0000..U+10FFFF range diff --git a/owner/fail_test.go b/owner/fail_test.go index acc94606441ec..84a57b43cd389 100644 --- a/owner/fail_test.go +++ b/owner/fail_test.go @@ -53,8 +53,10 @@ func (s *testSuite) SetUpSuite(c *C) { } func (s *testSuite) TearDownSuite(c *C) { - err := s.ln.Close() - c.Assert(err, IsNil) + if s.ln != nil { + err := s.ln.Close() + c.Assert(err, IsNil) + } } var ( diff --git a/parser/parser.y b/parser/parser.y index 1721e01a487ff..5af84bb1e3b29 100644 --- a/parser/parser.y +++ b/parser/parser.y @@ -4060,8 +4060,8 @@ CastType: x.Flag |= mysql.BinaryFlag } if x.Charset == "" { - x.Charset = charset.CharsetUTF8 - x.Collate = charset.CollationUTF8 + x.Charset = charset.CharsetUTF8MB4 + x.Collate = charset.CollationUTF8MB4 } $$ = x } @@ -4130,8 +4130,8 @@ CastType: { x := types.NewFieldType(mysql.TypeJSON) x.Flag |= mysql.BinaryFlag | (mysql.ParseToJSONFlag) - x.Charset = charset.CharsetUTF8 - x.Collate = charset.CollationUTF8 + x.Charset = charset.CharsetUTF8MB4 + x.Collate = charset.CollationUTF8MB4 $$ = x } diff --git a/planner/core/plan_to_pb_test.go b/planner/core/plan_to_pb_test.go index e507be3295f14..e03af344f4556 100644 --- a/planner/core/plan_to_pb_test.go +++ b/planner/core/plan_to_pb_test.go @@ -37,7 +37,7 @@ func (s *testDistsqlSuite) TestColumnToProto(c *C) { FieldType: *tp, } pc := model.ColumnToProto(col) - expect := &tipb.ColumnInfo{ColumnId: 0, Tp: 3, Collation: 83, ColumnLen: -1, Decimal: -1, Flag: 10, Elems: []string(nil), DefaultVal: []uint8(nil), PkHandle: false, XXX_unrecognized: []uint8(nil)} + expect := &tipb.ColumnInfo{ColumnId: 0, Tp: 3, Collation: mysql.DefaultCollationID, ColumnLen: -1, Decimal: -1, Flag: 10, Elems: []string(nil), DefaultVal: []uint8(nil), PkHandle: false, XXX_unrecognized: []uint8(nil)} c.Assert(pc, DeepEquals, expect) cols := []*model.ColumnInfo{col, col} diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index f54675f142d74..3fe981cb9c9ed 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -29,6 +29,7 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/ranger" "github.com/pkg/errors" ) @@ -835,8 +836,8 @@ func buildColumn(tableName, name string, tp byte, size int) *expression.Column { cs, cl := types.DefaultCharsetForType(tp) flag := mysql.UnsignedFlag if tp == mysql.TypeVarchar || tp == mysql.TypeBlob { - cs = mysql.DefaultCharset - cl = mysql.DefaultCollationName + cs = charset.CharsetUTF8MB4 + cl = charset.CollationUTF8MB4 flag = 0 } diff --git a/server/tidb_test.go b/server/tidb_test.go index db9c56cd77541..ffaae0657856f 100644 --- a/server/tidb_test.go +++ b/server/tidb_test.go @@ -511,7 +511,7 @@ func (ts *TidbTestSuite) TestFieldList(c *C) { case 10, 11, 12, 15, 16: // c_char char(20), c_varchar varchar(20), c_text_d text, // c_set set('a', 'b', 'c'), c_enum enum('a', 'b', 'c') - c.Assert(col.Charset, Equals, uint16(tmysql.CharsetIDs["utf8"]), Commentf("index %d", i)) + c.Assert(col.Charset, Equals, uint16(tmysql.CharsetIDs[tmysql.DefaultCharset]), Commentf("index %d", i)) continue } diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index b35e91cb8a1e6..383b45ff08bc1 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -21,7 +21,6 @@ import ( "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" - "github.com/pingcap/tidb/util/charset" ) // ScopeFlag is for system variable whether can be changed in global/session dynamically or not. @@ -164,7 +163,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "innodb_max_undo_log_size", ""}, {ScopeGlobal | ScopeSession, "range_alloc_block_size", "4096"}, {ScopeGlobal, ConnectTimeout, "10"}, - {ScopeGlobal | ScopeSession, "collation_server", charset.CollationUTF8}, + {ScopeGlobal | ScopeSession, "collation_server", mysql.DefaultCollationName}, {ScopeNone, "have_rtree_keys", "YES"}, {ScopeGlobal, "innodb_old_blocks_pct", "37"}, {ScopeGlobal, "innodb_file_format", "Antelope"}, @@ -296,7 +295,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, "query_cache_wlock_invalidate", "OFF"}, {ScopeGlobal | ScopeSession, "sql_buffer_result", "OFF"}, {ScopeGlobal | ScopeSession, "character_set_filesystem", "binary"}, - {ScopeGlobal | ScopeSession, "collation_database", charset.CollationUTF8}, + {ScopeGlobal | ScopeSession, "collation_database", mysql.DefaultCollationName}, {ScopeGlobal | ScopeSession, "auto_increment_increment", "1"}, {ScopeGlobal | ScopeSession, "max_heap_table_size", "16777216"}, {ScopeGlobal | ScopeSession, "div_precision_increment", "4"}, @@ -317,7 +316,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "innodb_purge_batch_size", "300"}, {ScopeNone, "have_profiling", "NO"}, {ScopeGlobal, "slave_checkpoint_group", "512"}, - {ScopeGlobal | ScopeSession, "character_set_client", charset.CharsetUTF8}, + {ScopeGlobal | ScopeSession, "character_set_client", mysql.DefaultCharset}, {ScopeNone, "slave_load_tmpdir", "/var/tmp/"}, {ScopeGlobal, "innodb_buffer_pool_dump_now", "OFF"}, {ScopeGlobal, "relay_log_purge", "ON"}, @@ -392,7 +391,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, "binlog_direct_non_transactional_updates", "OFF"}, {ScopeGlobal, "innodb_change_buffering", "all"}, {ScopeGlobal | ScopeSession, "sql_big_selects", "ON"}, - {ScopeGlobal | ScopeSession, CharacterSetResults, charset.CharsetUTF8}, + {ScopeGlobal | ScopeSession, CharacterSetResults, mysql.DefaultCharset}, {ScopeGlobal, "innodb_max_purge_lag_delay", "0"}, {ScopeGlobal | ScopeSession, "session_track_schema", ""}, {ScopeGlobal, "innodb_io_capacity_max", "2000"}, @@ -405,7 +404,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "innodb_buffer_pool_load_abort", "OFF"}, {ScopeGlobal | ScopeSession, "tx_isolation", "REPEATABLE-READ"}, {ScopeGlobal | ScopeSession, "transaction_isolation", "REPEATABLE-READ"}, - {ScopeGlobal | ScopeSession, "collation_connection", charset.CollationUTF8}, + {ScopeGlobal | ScopeSession, "collation_connection", mysql.DefaultCollationName}, {ScopeGlobal, "rpl_semi_sync_master_timeout", ""}, {ScopeGlobal | ScopeSession, "transaction_prealloc_size", "4096"}, {ScopeNone, "slave_skip_errors", "OFF"}, @@ -500,7 +499,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "max_points_in_geometry", ""}, {ScopeGlobal, "innodb_stats_sample_pages", "8"}, {ScopeGlobal | ScopeSession, "profiling_history_size", "15"}, - {ScopeGlobal | ScopeSession, "character_set_database", charset.CharsetUTF8}, + {ScopeGlobal | ScopeSession, "character_set_database", mysql.DefaultCharset}, {ScopeNone, "have_symlink", "YES"}, {ScopeGlobal | ScopeSession, "storage_engine", "InnoDB"}, {ScopeGlobal | ScopeSession, "sql_log_off", "OFF"}, @@ -579,10 +578,10 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal, "flush", "OFF"}, {ScopeGlobal | ScopeSession, "eq_range_index_dive_limit", "10"}, {ScopeNone, "performance_schema_events_stages_history_size", "10"}, - {ScopeGlobal | ScopeSession, "character_set_connection", charset.CharsetUTF8}, + {ScopeGlobal | ScopeSession, "character_set_connection", mysql.DefaultCharset}, {ScopeGlobal, "myisam_use_mmap", "OFF"}, {ScopeGlobal | ScopeSession, "ndb_join_pushdown", ""}, - {ScopeGlobal | ScopeSession, "character_set_server", charset.CharsetUTF8}, + {ScopeGlobal | ScopeSession, "character_set_server", mysql.DefaultCharset}, {ScopeGlobal, "validate_password_special_char_count", "1"}, {ScopeNone, "performance_schema_max_thread_instances", "402"}, {ScopeGlobal, "slave_rows_search_algorithms", "TABLE_SCAN,INDEX_SCAN"}, diff --git a/store/mockstore/mocktikv/analyze.go b/store/mockstore/mocktikv/analyze.go index bbda6c3020b00..66676123666ca 100644 --- a/store/mockstore/mocktikv/analyze.go +++ b/store/mockstore/mocktikv/analyze.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/types" - "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" @@ -144,7 +143,7 @@ func (h *rpcHandler) handleAnalyzeColumnsReq(req *coprocessor.Request, analyzeRe for i := range e.fields { rf := new(ast.ResultField) rf.Column = new(model.ColumnInfo) - rf.Column.FieldType = types.FieldType{Tp: mysql.TypeBlob, Flen: mysql.MaxBlobWidth, Charset: charset.CharsetUTF8, Collate: charset.CollationUTF8} + rf.Column.FieldType = types.FieldType{Tp: mysql.TypeBlob, Flen: mysql.MaxBlobWidth, Charset: mysql.DefaultCharset, Collate: mysql.DefaultCollationName} e.fields[i] = rf } diff --git a/table/tables/gen_expr.go b/table/tables/gen_expr.go index fa94ca009c74d..32376e0e9b739 100644 --- a/table/tables/gen_expr.go +++ b/table/tables/gen_expr.go @@ -19,14 +19,10 @@ import ( "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/parser" + "github.com/pingcap/tidb/util/charset" "github.com/pkg/errors" ) -// getDefaultCharsetAndCollate is copyed from ddl/ddl_api.go. -func getDefaultCharsetAndCollate() (string, string) { - return "utf8", "utf8_bin" -} - // nameResolver is the visitor to resolve table name and column name. // it combines TableInfo and ColumnInfo to a generation expression. type nameResolver struct { @@ -64,7 +60,7 @@ func (nr *nameResolver) Leave(inNode ast.Node) (node ast.Node, ok bool) { // it into ast.ExprNode. This function is for that. func parseExpression(expr string) (node ast.ExprNode, err error) { expr = fmt.Sprintf("select %s", expr) - charset, collation := getDefaultCharsetAndCollate() + charset, collation := charset.GetDefaultCharsetAndCollate() stmts, err := parser.New().Parse(expr, charset, collation) if err == nil { node = stmts[0].(*ast.SelectStmt).Fields.Fields[0].Expr diff --git a/types/field_type.go b/types/field_type.go index bb247ba8e7e20..184c5e9dfe6e1 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -285,7 +285,7 @@ func (ft *FieldType) FormatAsCastType(w io.Writer) { if ft.Flag&mysql.BinaryFlag != 0 { fmt.Fprint(w, " BINARY") } - if ft.Charset != charset.CharsetBin && ft.Charset != charset.CharsetUTF8 { + if ft.Charset != charset.CharsetBin && ft.Charset != mysql.DefaultCharset { fmt.Fprintf(w, " %s", ft.Charset) } case mysql.TypeDate: @@ -365,8 +365,8 @@ func DefaultTypeForValue(value interface{}, tp *FieldType) { // TODO: tp.Flen should be len(x) * 3 (max bytes length of CharsetUTF8) tp.Flen = len(x) tp.Decimal = UnspecifiedLength - tp.Charset = mysql.DefaultCharset - tp.Collate = mysql.DefaultCollationName + tp.Charset = charset.CharsetUTF8MB4 + tp.Collate = charset.CollationUTF8MB4 case float64: tp.Tp = mysql.TypeDouble s := strconv.FormatFloat(x, 'f', -1, 64) diff --git a/types/field_type_test.go b/types/field_type_test.go index 71a6ea2983f55..4ec09fae5265e 100644 --- a/types/field_type_test.go +++ b/types/field_type_test.go @@ -172,7 +172,7 @@ func (s *testFieldTypeSuite) TestDefaultTypeForValue(c *C) { {nil, mysql.TypeNull, 0, 0, charset.CharsetBin, charset.CharsetBin, mysql.BinaryFlag}, {1, mysql.TypeLonglong, 1, 0, charset.CharsetBin, charset.CharsetBin, mysql.BinaryFlag}, {uint64(1), mysql.TypeLonglong, 1, 0, charset.CharsetBin, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag}, - {"abc", mysql.TypeVarString, 3, UnspecifiedLength, charset.CharsetUTF8, charset.CollationUTF8, 0}, + {"abc", mysql.TypeVarString, 3, UnspecifiedLength, charset.CharsetUTF8MB4, charset.CollationUTF8MB4, 0}, {1.1, mysql.TypeDouble, 3, -1, charset.CharsetBin, charset.CharsetBin, mysql.BinaryFlag}, {[]byte("abc"), mysql.TypeBlob, 3, UnspecifiedLength, charset.CharsetBin, charset.CharsetBin, mysql.BinaryFlag}, {HexLiteral{}, mysql.TypeVarString, 0, 0, charset.CharsetBin, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag}, diff --git a/util/charset/charset.go b/util/charset/charset.go index 6967b9537a65c..7d0ec7e3e2f85 100644 --- a/util/charset/charset.go +++ b/util/charset/charset.go @@ -115,6 +115,11 @@ func GetDefaultCollation(charset string) (string, error) { return c.DefaultCollation, nil } +// GetDefaultCharsetAndCollate returns the default charset and collation. +func GetDefaultCharsetAndCollate() (string, string) { + return mysql.DefaultCharset, mysql.DefaultCollationName +} + // GetCharsetInfo returns charset and collation for cs as name. func GetCharsetInfo(cs string) (string, string, error) { c, ok := charsets[strings.ToLower(cs)] From cd01346811d47293650453a8fa8b1ce2760cd454 Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 22 Oct 2018 11:11:11 +0800 Subject: [PATCH 02/11] address comment --- types/field_type.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/field_type.go b/types/field_type.go index 184c5e9dfe6e1..c689ef37b216b 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -365,8 +365,7 @@ func DefaultTypeForValue(value interface{}, tp *FieldType) { // TODO: tp.Flen should be len(x) * 3 (max bytes length of CharsetUTF8) tp.Flen = len(x) tp.Decimal = UnspecifiedLength - tp.Charset = charset.CharsetUTF8MB4 - tp.Collate = charset.CollationUTF8MB4 + tp.Charset, tp.Collate = charset.GetDefaultCharsetAndCollate() case float64: tp.Tp = mysql.TypeDouble s := strconv.FormatFloat(x, 'f', -1, 64) From d30424c6c2c53810159d38f5dcd71f07e556e35c Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 5 Nov 2018 17:21:13 +0800 Subject: [PATCH 03/11] remove parser --- parser/parser.y | 7210 ------------------------------------ parser/types/field_type.go | 258 -- 2 files changed, 7468 deletions(-) delete mode 100644 parser/parser.y delete mode 100644 parser/types/field_type.go diff --git a/parser/parser.y b/parser/parser.y deleted file mode 100644 index 3beb0fbd9ca0a..0000000000000 --- a/parser/parser.y +++ /dev/null @@ -1,7210 +0,0 @@ -%{ -// Copyright 2013 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSES/QL-LICENSE file. - -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -// Initial yacc source generated by ebnf2y[1] -// at 2013-10-04 23:10:47.861401015 +0200 CEST -// -// $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _ -// -// [1]: http://github.com/cznic/ebnf2y - -package parser - -import ( - "strings" - - "github.com/pingcap/tidb/mysql" - "github.com/pingcap/tidb/ast" - "github.com/pingcap/tidb/model" - "github.com/pingcap/tidb/parser/opcode" - "github.com/pingcap/tidb/util/auth" - "github.com/pingcap/tidb/util/charset" - "github.com/pingcap/tidb/parser/types" -) - -%} - -%union { - offset int // offset - item interface{} - ident string - expr ast.ExprNode - statement ast.StmtNode -} - -%token - /*yy:token "%c" */ identifier "identifier" - /*yy:token "_%c" */ underscoreCS "UNDERSCORE_CHARSET" - /*yy:token "\"%c\"" */ stringLit "string literal" - singleAtIdentifier "identifier with single leading at" - doubleAtIdentifier "identifier with double leading at" - invalid "a special token never used by parser, used by lexer to indicate error" - hintBegin "hintBegin is a virtual token for optimizer hint grammar" - hintEnd "hintEnd is a virtual token for optimizer hint grammar" - andand "&&" - pipes "||" - - /* The following tokens belong to ODBCDateTimeType. */ - odbcDateType "d" - odbcTimeType "t" - odbcTimestampType "ts" - - /* The following tokens belong to ReservedKeyword. */ - add "ADD" - all "ALL" - alter "ALTER" - analyze "ANALYZE" - and "AND" - as "AS" - asc "ASC" - between "BETWEEN" - bigIntType "BIGINT" - binaryType "BINARY" - blobType "BLOB" - both "BOTH" - by "BY" - cascade "CASCADE" - caseKwd "CASE" - change "CHANGE" - character "CHARACTER" - charType "CHAR" - check "CHECK" - collate "COLLATE" - column "COLUMN" - constraint "CONSTRAINT" - convert "CONVERT" - create "CREATE" - cross "CROSS" - currentDate "CURRENT_DATE" - currentTime "CURRENT_TIME" - currentTs "CURRENT_TIMESTAMP" - currentUser "CURRENT_USER" - database "DATABASE" - databases "DATABASES" - dayHour "DAY_HOUR" - dayMicrosecond "DAY_MICROSECOND" - dayMinute "DAY_MINUTE" - daySecond "DAY_SECOND" - decimalType "DECIMAL" - defaultKwd "DEFAULT" - delayed "DELAYED" - deleteKwd "DELETE" - desc "DESC" - describe "DESCRIBE" - distinct "DISTINCT" - distinctRow "DISTINCTROW" - div "DIV" - doubleType "DOUBLE" - drop "DROP" - dual "DUAL" - elseKwd "ELSE" - enclosed "ENCLOSED" - escaped "ESCAPED" - exists "EXISTS" - explain "EXPLAIN" - falseKwd "FALSE" - floatType "FLOAT" - forKwd "FOR" - force "FORCE" - foreign "FOREIGN" - from "FROM" - fulltext "FULLTEXT" - generated "GENERATED" - grant "GRANT" - group "GROUP" - having "HAVING" - highPriority "HIGH_PRIORITY" - hourMicrosecond "HOUR_MICROSECOND" - hourMinute "HOUR_MINUTE" - hourSecond "HOUR_SECOND" - ifKwd "IF" - ignore "IGNORE" - in "IN" - index "INDEX" - infile "INFILE" - inner "INNER" - integerType "INTEGER" - interval "INTERVAL" - into "INTO" - is "IS" - insert "INSERT" - intType "INT" - int1Type "INT1" - int2Type "INT2" - int3Type "INT3" - int4Type "INT4" - int8Type "INT8" - join "JOIN" - key "KEY" - keys "KEYS" - kill "KILL" - leading "LEADING" - left "LEFT" - like "LIKE" - limit "LIMIT" - lines "LINES" - load "LOAD" - localTime "LOCALTIME" - localTs "LOCALTIMESTAMP" - lock "LOCK" - longblobType "LONGBLOB" - longtextType "LONGTEXT" - lowPriority "LOW_PRIORITY" - maxValue "MAXVALUE" - mediumblobType "MEDIUMBLOB" - mediumIntType "MEDIUMINT" - mediumtextType "MEDIUMTEXT" - minuteMicrosecond "MINUTE_MICROSECOND" - minuteSecond "MINUTE_SECOND" - mod "MOD" - not "NOT" - noWriteToBinLog "NO_WRITE_TO_BINLOG" - null "NULL" - numericType "NUMERIC" - nvarcharType "NVARCHAR" - on "ON" - option "OPTION" - or "OR" - order "ORDER" - outer "OUTER" - packKeys "PACK_KEYS" - partition "PARTITION" - precisionType "PRECISION" - primary "PRIMARY" - procedure "PROCEDURE" - shardRowIDBits "SHARD_ROW_ID_BITS" - rangeKwd "RANGE" - read "READ" - realType "REAL" - references "REFERENCES" - regexpKwd "REGEXP" - rename "RENAME" - repeat "REPEAT" - replace "REPLACE" - restrict "RESTRICT" - revoke "REVOKE" - right "RIGHT" - rlike "RLIKE" - secondMicrosecond "SECOND_MICROSECOND" - selectKwd "SELECT" - set "SET" - show "SHOW" - smallIntType "SMALLINT" - sql "SQL" - sqlCalcFoundRows "SQL_CALC_FOUND_ROWS" - starting "STARTING" - straightJoin "STRAIGHT_JOIN" - tableKwd "TABLE" - stored "STORED" - terminated "TERMINATED" - then "THEN" - tinyblobType "TINYBLOB" - tinyIntType "TINYINT" - tinytextType "TINYTEXT" - to "TO" - trailing "TRAILING" - trigger "TRIGGER" - trueKwd "TRUE" - unique "UNIQUE" - union "UNION" - unlock "UNLOCK" - unsigned "UNSIGNED" - update "UPDATE" - usage "USAGE" - use "USE" - using "USING" - utcDate "UTC_DATE" - utcTimestamp "UTC_TIMESTAMP" - utcTime "UTC_TIME" - values "VALUES" - long "LONG" - varcharType "VARCHAR" - varbinaryType "VARBINARY" - virtual "VIRTUAL" - when "WHEN" - where "WHERE" - write "WRITE" - with "WITH" - xor "XOR" - yearMonth "YEAR_MONTH" - zerofill "ZEROFILL" - natural "NATURAL" - - /* The following tokens belong to UnReservedKeyword. */ - action "ACTION" - after "AFTER" - always "ALWAYS" - algorithm "ALGORITHM" - any "ANY" - ascii "ASCII" - autoIncrement "AUTO_INCREMENT" - avgRowLength "AVG_ROW_LENGTH" - avg "AVG" - begin "BEGIN" - binlog "BINLOG" - bitType "BIT" - booleanType "BOOLEAN" - boolType "BOOL" - btree "BTREE" - byteType "BYTE" - cascaded "CASCADED" - charsetKwd "CHARSET" - checksum "CHECKSUM" - cleanup "CLEANUP" - client "CLIENT" - coalesce "COALESCE" - collation "COLLATION" - columns "COLUMNS" - comment "COMMENT" - commit "COMMIT" - committed "COMMITTED" - compact "COMPACT" - compressed "COMPRESSED" - compression "COMPRESSION" - connection "CONNECTION" - consistent "CONSISTENT" - day "DAY" - data "DATA" - dateType "DATE" - datetimeType "DATETIME" - deallocate "DEALLOCATE" - definer "DEFINER" - delayKeyWrite "DELAY_KEY_WRITE" - disable "DISABLE" - do "DO" - duplicate "DUPLICATE" - dynamic "DYNAMIC" - enable "ENABLE" - end "END" - engine "ENGINE" - engines "ENGINES" - enum "ENUM" - event "EVENT" - events "EVENTS" - escape "ESCAPE" - exclusive "EXCLUSIVE" - execute "EXECUTE" - fields "FIELDS" - first "FIRST" - fixed "FIXED" - flush "FLUSH" - format "FORMAT" - full "FULL" - function "FUNCTION" - grants "GRANTS" - hash "HASH" - hour "HOUR" - identified "IDENTIFIED" - isolation "ISOLATION" - indexes "INDEXES" - invoker "INVOKER" - jsonType "JSON" - keyBlockSize "KEY_BLOCK_SIZE" - local "LOCAL" - less "LESS" - level "LEVEL" - master "MASTER" - microsecond "MICROSECOND" - minute "MINUTE" - mode "MODE" - modify "MODIFY" - month "MONTH" - maxRows "MAX_ROWS" - maxConnectionsPerHour "MAX_CONNECTIONS_PER_HOUR" - maxQueriesPerHour "MAX_QUERIES_PER_HOUR" - maxUpdatesPerHour "MAX_UPDATES_PER_HOUR" - maxUserConnections "MAX_USER_CONNECTIONS" - merge "MERGE" - minRows "MIN_ROWS" - names "NAMES" - national "NATIONAL" - no "NO" - none "NONE" - offset "OFFSET" - only "ONLY" - password "PASSWORD" - partitions "PARTITIONS" - pipesAsOr - plugins "PLUGINS" - prepare "PREPARE" - privileges "PRIVILEGES" - process "PROCESS" - processlist "PROCESSLIST" - profiles "PROFILES" - quarter "QUARTER" - query "QUERY" - queries "QUERIES" - quick "QUICK" - recover "RECOVER" - redundant "REDUNDANT" - reload "RELOAD" - repeatable "REPEATABLE" - replication "REPLICATION" - reverse "REVERSE" - rollback "ROLLBACK" - routine "ROUTINE" - row "ROW" - rowCount "ROW_COUNT" - rowFormat "ROW_FORMAT" - second "SECOND" - security "SECURITY" - separator "SEPARATOR" - serializable "SERIALIZABLE" - session "SESSION" - share "SHARE" - shared "SHARED" - signed "SIGNED" - slave "SLAVE" - slow "SLOW" - snapshot "SNAPSHOT" - sqlCache "SQL_CACHE" - sqlNoCache "SQL_NO_CACHE" - start "START" - statsPersistent "STATS_PERSISTENT" - status "STATUS" - subpartition "SUBPARTITION" - subpartitions "SUBPARTITIONS" - super "SUPER" - some "SOME" - global "GLOBAL" - tables "TABLES" - tablespace "TABLESPACE" - temporary "TEMPORARY" - temptable "TEMPTABLE" - textType "TEXT" - than "THAN" - timeType "TIME" - timestampType "TIMESTAMP" - trace "TRACE" - transaction "TRANSACTION" - triggers "TRIGGERS" - truncate "TRUNCATE" - uncommitted "UNCOMMITTED" - unknown "UNKNOWN" - user "USER" - undefined "UNDEFINED" - value "VALUE" - variables "VARIABLES" - view "VIEW" - warnings "WARNINGS" - identSQLErrors "ERRORS" - week "WEEK" - yearType "YEAR" - - /* The following tokens belong to NotKeywordToken. */ - addDate "ADDDATE" - bitAnd "BIT_AND" - bitOr "BIT_OR" - bitXor "BIT_XOR" - cast "CAST" - copyKwd "COPY" - count "COUNT" - curTime "CURTIME" - dateAdd "DATE_ADD" - dateSub "DATE_SUB" - extract "EXTRACT" - getFormat "GET_FORMAT" - groupConcat "GROUP_CONCAT" - inplace "INPLACE" - internal "INTERNAL" - min "MIN" - max "MAX" - maxExecutionTime "MAX_EXECUTION_TIME" - now "NOW" - position "POSITION" - recent "RECENT" - subDate "SUBDATE" - sum "SUM" - substring "SUBSTRING" - timestampAdd "TIMESTAMPADD" - timestampDiff "TIMESTAMPDIFF" - top "TOP" - trim "TRIM" - - /* The following tokens belong to TiDBKeyword. */ - admin "ADMIN" - buckets "BUCKETS" - cancel "CANCEL" - ddl "DDL" - jobs "JOBS" - job "JOB" - stats "STATS" - statsMeta "STATS_META" - statsHistograms "STATS_HISTOGRAMS" - statsBuckets "STATS_BUCKETS" - statsHealthy "STATS_HEALTHY" - tidb "TIDB" - tidbHJ "TIDB_HJ" - tidbSMJ "TIDB_SMJ" - tidbINLJ "TIDB_INLJ" - - builtinAddDate - builtinBitAnd - builtinBitOr - builtinBitXor - builtinCast - builtinCount - builtinCurDate - builtinCurTime - builtinDateAdd - builtinDateSub - builtinExtract - builtinGroupConcat - builtinMax - builtinMin - builtinNow - builtinPosition - builtinStddevPop - builtinSubDate - builtinSubstring - builtinSum - builtinSysDate - builtinTrim - builtinUser - builtinVarPop - builtinVarSamp - -%token - - /*yy:token "1.%d" */ floatLit "floating-point literal" - /*yy:token "1.%d" */ decLit "decimal literal" - /*yy:token "%d" */ intLit "integer literal" - /*yy:token "%x" */ hexLit "hexadecimal literal" - /*yy:token "%b" */ bitLit "bit literal" - - andnot "&^" - assignmentEq ":=" - eq "=" - ge ">=" - le "<=" - jss "->" - juss "->>" - lsh "<<" - neq "!=" - neqSynonym "<>" - nulleq "<=>" - paramMarker "?" - rsh ">>" - -%token not2 - -%type - Expression "expression" - MaxValueOrExpression "maxvalue or expression" - BoolPri "boolean primary expression" - ExprOrDefault "expression or default" - PredicateExpr "Predicate expression factor" - SetExpr "Set variable statement value's expression" - BitExpr "bit expression" - SimpleExpr "simple expression" - SimpleIdent "Simple Identifier expression" - SumExpr "aggregate functions" - FunctionCallGeneric "Function call with Identifier" - FunctionCallKeyword "Function call with keyword as function name" - FunctionCallNonKeyword "Function call with nonkeyword as function name" - Literal "literal value" - Variable "User or system variable" - SystemVariable "System defined variable name" - UserVariable "User defined variable name" - SubSelect "Sub Select" - StringLiteral "text literal" - ExpressionOpt "Optional expression" - SignedLiteral "Literal or NumLiteral with sign" - DefaultValueExpr "DefaultValueExpr(Now or Signed Literal)" - NowSymOptionFraction "NowSym with optional fraction part" - -%type - AdminStmt "Check table statement or show ddl statement" - AlterTableStmt "Alter table statement" - AlterUserStmt "Alter user statement" - AnalyzeTableStmt "Analyze table statement" - BeginTransactionStmt "BEGIN TRANSACTION statement" - BinlogStmt "Binlog base64 statement" - CommitStmt "COMMIT statement" - CreateTableStmt "CREATE TABLE statement" - CreateViewStmt "CREATE VIEW stetement" - CreateUserStmt "CREATE User statement" - CreateDatabaseStmt "Create Database Statement" - CreateIndexStmt "CREATE INDEX statement" - DoStmt "Do statement" - DropDatabaseStmt "DROP DATABASE statement" - DropIndexStmt "DROP INDEX statement" - DropStatsStmt "DROP STATS statement" - DropTableStmt "DROP TABLE statement" - DropUserStmt "DROP USER" - DropViewStmt "DROP VIEW statement" - DeallocateStmt "Deallocate prepared statement" - DeleteFromStmt "DELETE FROM statement" - EmptyStmt "empty statement" - ExecuteStmt "Execute statement" - ExplainStmt "EXPLAIN statement" - ExplainableStmt "explainable statement" - FlushStmt "Flush statement" - GrantStmt "Grant statement" - InsertIntoStmt "INSERT INTO statement" - KillStmt "Kill statement" - LoadDataStmt "Load data statement" - LoadStatsStmt "Load statistic statement" - LockTablesStmt "Lock tables statement" - PreparedStmt "PreparedStmt" - SelectStmt "SELECT statement" - RenameTableStmt "rename table statement" - ReplaceIntoStmt "REPLACE INTO statement" - RevokeStmt "Revoke statement" - RollbackStmt "ROLLBACK statement" - SetStmt "Set variable statement" - ShowStmt "Show engines/databases/tables/columns/warnings/status statement" - Statement "statement" - TraceStmt "TRACE statement" - TraceableStmt "traceable statment" - TruncateTableStmt "TRUNCATE TABLE statement" - UnlockTablesStmt "Unlock tables statement" - UpdateStmt "UPDATE statement" - UnionStmt "Union select state ment" - UseStmt "USE statement" - -%type - AdminShowSlow "Admin Show Slow statement" - AlterTableOptionListOpt "alter table option list opt" - AlterTableSpec "Alter table specification" - AlterTableSpecList "Alter table specification list" - AnyOrAll "Any or All for subquery" - Assignment "assignment" - AssignmentList "assignment list" - AssignmentListOpt "assignment list opt" - AuthOption "User auth option" - AuthString "Password string value" - OptionalBraces "optional braces" - CastType "Cast function target type" - CharsetName "Character set name" - ColumnDef "table column definition" - ColumnDefList "table column definition list" - ColumnName "column name" - ColumnNameList "column name list" - ColumnList "column list" - ColumnNameListOpt "column name list opt" - ColumnNameListOptWithBrackets "column name list opt with brackets" - ColumnSetValue "insert statement set value by column name" - ColumnSetValueList "insert statement set value by column name list" - CompareOp "Compare opcode" - ColumnOption "column definition option" - ColumnOptionList "column definition option list" - VirtualOrStored "indicate generated column is stored or not" - ColumnOptionListOpt "optional column definition option list" - Constraint "table constraint" - ConstraintElem "table constraint element" - ConstraintKeywordOpt "Constraint Keyword or empty" - CreateIndexStmtUnique "CREATE INDEX optional UNIQUE clause" - CreateTableOptionListOpt "create table option list opt" - CreateTableSelectOpt "Select/Union statement in CREATE TABLE ... SELECT" - DatabaseOption "CREATE Database specification" - DatabaseOptionList "CREATE Database specification list" - DatabaseOptionListOpt "CREATE Database specification list opt" - DBName "Database Name" - DistinctOpt "Explicit distinct option" - DefaultFalseDistinctOpt "Distinct option which defaults to false" - DefaultTrueDistinctOpt "Distinct option which defaults to true" - BuggyDefaultFalseDistinctOpt "Distinct option which accepts DISTINCT ALL and defaults to false" - Enclosed "Enclosed by" - EqOpt "= or empty" - EscapedTableRef "escaped table reference" - Escaped "Escaped by" - ExpressionList "expression list" - MaxValueOrExpressionList "maxvalue or expression list" - ExpressionListOpt "expression list opt" - FuncDatetimePrecListOpt "Function datetime precision list opt" - FuncDatetimePrecList "Function datetime precision list" - Field "field expression" - Fields "Fields clause" - FieldsTerminated "Fields terminated by" - FieldAsName "Field alias name" - FieldAsNameOpt "Field alias name opt" - FieldList "field expression list" - FlushOption "Flush option" - TableRefsClause "Table references clause" - FuncDatetimePrec "Function datetime precision" - GlobalScope "The scope of variable" - GroupByClause "GROUP BY clause" - HashString "Hashed string" - HavingClause "HAVING clause" - HandleRange "handle range" - HandleRangeList "handle range list" - IfExists "If Exists" - IfNotExists "If Not Exists" - IgnoreOptional "IGNORE or empty" - IndexColName "Index column name" - IndexColNameList "List of index column name" - IndexHint "index hint" - IndexHintList "index hint list" - IndexHintListOpt "index hint list opt" - IndexHintScope "index hint scope" - IndexHintType "index hint type" - IndexName "index name" - IndexNameList "index name list" - IndexOption "Index Option" - IndexOptionList "Index Option List or empty" - IndexType "index type" - IndexTypeOpt "Optional index type" - InsertValues "Rest part of INSERT/REPLACE INTO statement" - JoinTable "join table" - JoinType "join type" - KillOrKillTiDB "Kill or Kill TiDB" - LikeEscapeOpt "like escape option" - LikeTableWithOrWithoutParen "LIKE table_name or ( LIKE table_name )" - LimitClause "LIMIT clause" - LimitOption "Limit option could be integer or parameter marker." - Lines "Lines clause" - LinesTerminated "Lines terminated by" - LocalOpt "Local opt" - LockClause "Alter table lock clause" - MaxNumBuckets "Max number of buckets" - NumLiteral "Num/Int/Float/Decimal Literal" - NoWriteToBinLogAliasOpt "NO_WRITE_TO_BINLOG alias LOCAL or empty" - ObjectType "Grant statement object type" - OnDuplicateKeyUpdate "ON DUPLICATE KEY UPDATE value list" - DuplicateOpt "[IGNORE|REPLACE] in CREATE TABLE ... SELECT statement" - OptFull "Full or empty" - Order "ORDER BY clause optional collation specification" - OrderBy "ORDER BY clause" - OrReplace "or replace" - ByItem "BY item" - OrderByOptional "Optional ORDER BY clause optional" - ByList "BY list" - QuickOptional "QUICK or empty" - PartitionDefinition "Partition definition" - PartitionDefinitionList "Partition definition list" - PartitionDefinitionListOpt "Partition definition list option" - PartitionOpt "Partition option" - PartitionNameList "Partition name list" - PartitionNumOpt "PARTITION NUM option" - PartDefValuesOpt "VALUES {LESS THAN {(expr | value_list) | MAXVALUE} | IN {value_list}" - PartDefOptionsOpt "PartDefOptionList option" - PartDefOptionList "PartDefOption list" - PartDefOption "COMMENT [=] xxx | TABLESPACE [=] tablespace_name | ENGINE [=] xxx" - PasswordOpt "Password option" - ColumnPosition "Column position [First|After ColumnName]" - PrepareSQL "Prepare statement sql string" - PriorityOpt "Statement priority option" - PrivElem "Privilege element" - PrivElemList "Privilege element list" - PrivLevel "Privilege scope" - PrivType "Privilege type" - ReferDef "Reference definition" - OnDeleteOpt "optional ON DELETE clause" - OnUpdateOpt "optional ON UPDATE clause" - OptGConcatSeparator "optional GROUP_CONCAT SEPARATOR" - ReferOpt "reference option" - RowFormat "Row format option" - RowValue "Row value" - SelectLockOpt "FOR UPDATE or LOCK IN SHARE MODE," - SelectStmtCalcFoundRows "SELECT statement optional SQL_CALC_FOUND_ROWS" - SelectStmtSQLCache "SELECT statement optional SQL_CAHCE/SQL_NO_CACHE" - SelectStmtStraightJoin "SELECT statement optional STRAIGHT_JOIN" - SelectStmtFieldList "SELECT statement field list" - SelectStmtLimit "SELECT statement optional LIMIT clause" - SelectStmtOpts "Select statement options" - SelectStmtBasic "SELECT statement from constant value" - SelectStmtFromDual "SELECT statement from dual" - SelectStmtFromTable "SELECT statement from table" - SelectStmtGroup "SELECT statement optional GROUP BY clause" - ShowTargetFilterable "Show target that can be filtered by WHERE or LIKE" - ShowDatabaseNameOpt "Show tables/columns statement database name option" - ShowTableAliasOpt "Show table alias option" - ShowLikeOrWhereOpt "Show like or where clause option" - Starting "Starting by" - StatementList "statement list" - StatsPersistentVal "stats_persistent value" - StringName "string literal or identifier" - StringList "string list" - SubPartitionOpt "SubPartition option" - SubPartitionNumOpt "SubPartition NUM option" - Symbol "Constraint Symbol" - TableAsName "table alias name" - TableAsNameOpt "table alias name optional" - TableElement "table definition element" - TableElementList "table definition element list" - TableElementListOpt "table definition element list optional" - TableFactor "table factor" - TableLock "Table name and lock type" - TableLockList "Table lock list" - TableName "Table name" - TableNameList "Table name list" - TableNameListOpt "Table name list opt" - TableOption "create table option" - TableOptionList "create table option list" - TableRef "table reference" - TableRefs "table references" - TableToTable "rename table to table" - TableToTableList "rename table to table by list" - - TransactionChar "Transaction characteristic" - TransactionChars "Transaction characteristic list" - TrimDirection "Trim string direction" - UnionOpt "Union Option(empty/ALL/DISTINCT)" - UnionClauseList "Union select clause list" - UnionSelect "Union (select) item" - Username "Username" - UsernameList "UsernameList" - UserSpec "Username and auth option" - UserSpecList "Username and auth option list" - UserVariableList "User defined variable name list" - Values "values" - ValuesList "values list" - ValuesOpt "values optional" - VariableAssignment "set variable value" - VariableAssignmentList "set variable value list" - ViewAlgorithm "view algorithm" - ViewCheckOption "view check option" - ViewDefiner "view definer" - ViewName "view name" - ViewFieldList "create view statement field list" - ViewSQLSecurity "view sql security" - WhereClause "WHERE clause" - WhereClauseOptional "Optional WHERE clause" - WhenClause "When clause" - WhenClauseList "When clause list" - WithReadLockOpt "With Read Lock opt" - WithGrantOptionOpt "With Grant Option opt" - ElseOpt "Optional else clause" - Type "Types" - - BetweenOrNotOp "Between predicate" - IsOrNotOp "Is predicate" - InOrNotOp "In predicate" - LikeOrNotOp "Like predicate" - RegexpOrNotOp "Regexp predicate" - - NumericType "Numeric types" - IntegerType "Integer Types types" - BooleanType "Boolean Types types" - FixedPointType "Exact value types" - FloatingPointType "Approximate value types" - BitValueType "bit value types" - StringType "String types" - BlobType "Blob types" - TextType "Text types" - DateAndTimeType "Date and Time types" - - OptFieldLen "Field length or empty" - FieldLen "Field length" - FieldOpts "Field type definition option list" - FieldOpt "Field type definition option" - FloatOpt "Floating-point type option" - Precision "Floating-point precision option" - OptBinary "Optional BINARY" - OptBinMod "Optional BINARY mode" - OptCharset "Optional Character setting" - OptCollate "Optional Collate setting" - IgnoreLines "Ignore num(int) lines" - NUM "A number" - NumList "Some numbers" - LengthNum "Field length num(uint64)" - HintTableList "Table list in optimizer hint" - TableOptimizerHintOpt "Table level optimizer hint" - TableOptimizerHints "Table level optimizer hints" - TableOptimizerHintList "Table level optimizer hint list" - -%type - EQOrAssignmentEQ "= or :=" - AsOpt "AS or EmptyString" - KeyOrIndex "{KEY|INDEX}" - ColumnKeywordOpt "Column keyword or empty" - PrimaryOpt "Optional primary keyword" - NowSym "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP" - NowSymFunc "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP/NOW" - DefaultKwdOpt "optional DEFAULT keyword" - DatabaseSym "DATABASE or SCHEMA" - ExplainSym "EXPLAIN or DESCRIBE or DESC" - RegexpSym "REGEXP or RLIKE" - IntoOpt "INTO or EmptyString" - ValueSym "Value or Values" - Varchar "{NATIONAL VARCHAR|VARCHAR|NVARCHAR}" - TimeUnit "Time unit for 'DATE_ADD', 'DATE_SUB', 'ADDDATE', 'SUBDATE', 'EXTRACT'" - TimestampUnit "Time unit for 'TIMESTAMPADD' and 'TIMESTAMPDIFF'" - DeallocateSym "Deallocate or drop" - OuterOpt "optional OUTER clause" - CrossOpt "Cross join option" - TablesTerminalSym "{TABLE|TABLES}" - IsolationLevel "Isolation level" - ShowIndexKwd "Show index/indexs/key keyword" - DistinctKwd "DISTINCT/DISTINCTROW keyword" - FromOrIn "From or In" - OptTable "Optional table keyword" - OptInteger "Optional Integer keyword" - NationalOpt "National option" - CharsetKw "charset or charater set" - CommaOpt "optional comma" - LockType "Table locks type" - logAnd "logical and operator" - logOr "logical or operator" - FieldsOrColumns "Fields or columns" - GetFormatSelector "{DATE|DATETIME|TIME|TIMESTAMP}" - -%type - ODBCDateTimeType "ODBC type keywords for date and time literals" - Identifier "identifier or unreserved keyword" - NotKeywordToken "Tokens not mysql keyword but treated specially" - UnReservedKeyword "MySQL unreserved keywords" - TiDBKeyword "TiDB added keywords" - FunctionNameConflict "Built-in function call names which are conflict with keywords" - FunctionNameOptionalBraces "Function with optional braces, all of them are reserved keywords." - FunctionNameDatetimePrecision "Function with optional datetime precision, all of them are reserved keywords." - FunctionNameDateArith "Date arith function call names (date_add or date_sub)" - FunctionNameDateArithMultiForms "Date arith function call names (adddate or subdate)" - -%precedence empty - -%precedence sqlCache sqlNoCache -%precedence lowerThanIntervalKeyword -%precedence interval -%precedence lowerThanStringLitToken -%precedence stringLit -%precedence lowerThanSetKeyword -%precedence set -%precedence lowerThanInsertValues -%precedence insertValues -%precedence lowerThanCreateTableSelect -%precedence createTableSelect -%precedence lowerThanKey -%precedence key - -%left join straightJoin inner cross left right full natural -/* A dummy token to force the priority of TableRef production in a join. */ -%left tableRefPriority -%precedence lowerThanOn -%precedence on using -%right assignmentEq -%left pipes or pipesAsOr -%left xor -%left andand and -%left between -%precedence lowerThanEq -%left eq ge le neq neqSynonym '>' '<' is like in -%left '|' -%left '&' -%left rsh lsh -%left '-' '+' -%left '*' '/' '%' div mod -%left '^' -%left '~' neg -%right not not2 -%right collate - -%precedence '(' -%precedence quick -%precedence escape -%precedence lowerThanComma -%precedence ',' -%precedence higherThanComma - -%start Start - -%% - -Start: - StatementList - -/**************************************AlterTableStmt*************************************** - * See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html - *******************************************************************************************/ -AlterTableStmt: - "ALTER" IgnoreOptional "TABLE" TableName AlterTableSpecList - { - $$ = &ast.AlterTableStmt{ - Table: $4.(*ast.TableName), - Specs: $5.([]*ast.AlterTableSpec), - } - } -| "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList MaxNumBuckets - { - $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, PartitionNames: $7.([]model.CIStr), MaxNumBuckets: $8.(uint64),} - } -| "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList "INDEX" IndexNameList MaxNumBuckets - { - $$ = &ast.AnalyzeTableStmt{ - TableNames: []*ast.TableName{$4.(*ast.TableName)}, - PartitionNames: $7.([]model.CIStr), - IndexNames: $9.([]model.CIStr), - IndexFlag: true, - MaxNumBuckets: $10.(uint64), - } - } - -AlterTableSpec: - AlterTableOptionListOpt - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableOption, - Options:$1.([]*ast.TableOption), - } - } -| "CONVERT" "TO" CharsetKw CharsetName OptCollate - { - op := &ast.AlterTableSpec{ - Tp: ast.AlterTableOption, - Options:[]*ast.TableOption{{Tp: ast.TableOptionCharset, StrValue: $4.(string)}}, - } - if $5 != "" { - op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5.(string)}) - } - $$ = op - } -| "ADD" ColumnKeywordOpt ColumnDef ColumnPosition - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAddColumns, - NewColumns: []*ast.ColumnDef{$3.(*ast.ColumnDef)}, - Position: $4.(*ast.ColumnPosition), - } - } -| "ADD" ColumnKeywordOpt '(' ColumnDefList ')' - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAddColumns, - NewColumns: $4.([]*ast.ColumnDef), - } - } -| "ADD" Constraint - { - constraint := $2.(*ast.Constraint) - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAddConstraint, - Constraint: constraint, - } - } -| "ADD" "PARTITION" PartitionDefinitionListOpt - { - var defs []*ast.PartitionDefinition - if $3 != nil { - defs = $3.([]*ast.PartitionDefinition) - } - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAddPartitions, - PartDefinitions: defs, - } - } -| "DROP" ColumnKeywordOpt ColumnName RestrictOrCascadeOpt - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableDropColumn, - OldColumnName: $3.(*ast.ColumnName), - } - } -| "DROP" "PRIMARY" "KEY" - { - $$ = &ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey} - } -| "DROP" "PARTITION" Identifier - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableDropPartition, - Name: $3, - } - } -| "DROP" KeyOrIndex Identifier - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableDropIndex, - Name: $3, - } - } -| "DROP" "FOREIGN" "KEY" Symbol - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableDropForeignKey, - Name: $4.(string), - } - } -| "DISABLE" "KEYS" - { - $$ = &ast.AlterTableSpec{} - } -| "ENABLE" "KEYS" - { - $$ = &ast.AlterTableSpec{} - } -| "MODIFY" ColumnKeywordOpt ColumnDef ColumnPosition - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableModifyColumn, - NewColumns: []*ast.ColumnDef{$3.(*ast.ColumnDef)}, - Position: $4.(*ast.ColumnPosition), - } - } -| "CHANGE" ColumnKeywordOpt ColumnName ColumnDef ColumnPosition - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableChangeColumn, - OldColumnName: $3.(*ast.ColumnName), - NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)}, - Position: $5.(*ast.ColumnPosition), - } - } -| "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" SignedLiteral - { - option := &ast.ColumnOption{Expr: $6} - colDef := &ast.ColumnDef{ - Name: $3.(*ast.ColumnName), - Options: []*ast.ColumnOption{option}, - } - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAlterColumn, - NewColumns: []*ast.ColumnDef{colDef}, - } - } -| "ALTER" ColumnKeywordOpt ColumnName "DROP" "DEFAULT" - { - colDef := &ast.ColumnDef{ - Name: $3.(*ast.ColumnName), - } - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAlterColumn, - NewColumns: []*ast.ColumnDef{colDef}, - } - } -| "RENAME" "TO" TableName - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableRenameTable, - NewTable: $3.(*ast.TableName), - } - } -| "RENAME" TableName - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableRenameTable, - NewTable: $2.(*ast.TableName), - } - } -| "RENAME" "AS" TableName - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableRenameTable, - NewTable: $3.(*ast.TableName), - } - } -| "RENAME" KeyOrIndex Identifier "TO" Identifier - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableRenameIndex, - FromKey: model.NewCIStr($3), - ToKey: model.NewCIStr($5), - } - } -| LockClause - { - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableLock, - LockType: $1.(ast.LockType), - } - } -| "ALGORITHM" EqOpt AlterAlgorithm - { - // Parse it and ignore it. Just for compatibility. - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableAlgorithm, - } - } -| "FORCE" - { - // Parse it and ignore it. Just for compatibility. - $$ = &ast.AlterTableSpec{ - Tp: ast.AlterTableForce, - } - } - - -AlterAlgorithm: - "DEFAULT" | "INPLACE" | "COPY" - -LockClauseOpt: - {} -| LockClause {} - -LockClause: - "LOCK" eq "NONE" - { - $$ = ast.LockTypeNone - } -| "LOCK" eq "DEFAULT" - { - $$ = ast.LockTypeDefault - } -| "LOCK" eq "SHARED" - { - $$ = ast.LockTypeShared - } -| "LOCK" eq "EXCLUSIVE" - { - $$ = ast.LockTypeExclusive - } - -KeyOrIndex: "KEY" | "INDEX" - - -KeyOrIndexOpt: - {} -| KeyOrIndex - -ColumnKeywordOpt: - {} -| "COLUMN" - -ColumnPosition: - { - $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionNone} - } -| "FIRST" - { - $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionFirst} - } -| "AFTER" ColumnName - { - $$ = &ast.ColumnPosition{ - Tp: ast.ColumnPositionAfter, - RelativeColumn: $2.(*ast.ColumnName), - } - } - -AlterTableSpecList: - AlterTableSpec - { - $$ = []*ast.AlterTableSpec{$1.(*ast.AlterTableSpec)} - } -| AlterTableSpecList ',' AlterTableSpec - { - $$ = append($1.([]*ast.AlterTableSpec), $3.(*ast.AlterTableSpec)) - } - -PartitionNameList: - Identifier - { - $$ = []model.CIStr{model.NewCIStr($1)} - } -| PartitionNameList ',' Identifier - { - $$ = append($1.([]model.CIStr), model.NewCIStr($3)) - } - -ConstraintKeywordOpt: - { - $$ = nil - } -| "CONSTRAINT" - { - $$ = nil - } -| "CONSTRAINT" Symbol - { - $$ = $2.(string) - } - -Symbol: - Identifier - { - $$ = $1 - } - -/**************************************RenameTableStmt*************************************** - * See http://dev.mysql.com/doc/refman/5.7/en/rename-table.html - * - * TODO: refactor this when you are going to add full support for multiple schema changes. - * Currently it is only useful for syncer which depends heavily on tidb parser to do some dirty work. - *******************************************************************************************/ -RenameTableStmt: - "RENAME" "TABLE" TableToTableList - { - $$ = &ast.RenameTableStmt{ - OldTable: $3.([]*ast.TableToTable)[0].OldTable, - NewTable: $3.([]*ast.TableToTable)[0].NewTable, - TableToTables: $3.([]*ast.TableToTable), - } - } - -TableToTableList: - TableToTable - { - $$ = []*ast.TableToTable{$1.(*ast.TableToTable)} - } -| TableToTableList ',' TableToTable - { - $$ = append($1.([]*ast.TableToTable), $3.(*ast.TableToTable)) - } - -TableToTable: - TableName "TO" TableName - { - $$ = &ast.TableToTable{ - OldTable: $1.(*ast.TableName), - NewTable: $3.(*ast.TableName), - } - } - - -/*******************************************************************************************/ - -AnalyzeTableStmt: - "ANALYZE" "TABLE" TableNameList MaxNumBuckets - { - $$ = &ast.AnalyzeTableStmt{TableNames: $3.([]*ast.TableName), MaxNumBuckets: $4.(uint64)} - } -| "ANALYZE" "TABLE" TableName "INDEX" IndexNameList MaxNumBuckets - { - $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, IndexNames: $5.([]model.CIStr), IndexFlag: true, MaxNumBuckets: $6.(uint64)} - } -| "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList MaxNumBuckets - { - $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, PartitionNames: $5.([]model.CIStr), MaxNumBuckets: $6.(uint64),} - } -| "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList MaxNumBuckets - { - $$ = &ast.AnalyzeTableStmt{ - TableNames: []*ast.TableName{$3.(*ast.TableName)}, - PartitionNames: $5.([]model.CIStr), - IndexNames: $7.([]model.CIStr), - IndexFlag: true, - MaxNumBuckets: $8.(uint64), - } - } - -MaxNumBuckets: - { - $$ = uint64(0) - } -| "WITH" NUM "BUCKETS" - { - $$ = getUint64FromNUM($2) - } - -/*******************************************************************************************/ -Assignment: - ColumnName eq Expression - { - $$ = &ast.Assignment{Column: $1.(*ast.ColumnName), Expr:$3} - } - -AssignmentList: - Assignment - { - $$ = []*ast.Assignment{$1.(*ast.Assignment)} - } -| AssignmentList ',' Assignment - { - $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment)) - } - -AssignmentListOpt: - /* EMPTY */ - { - $$ = []*ast.Assignment{} - } -| AssignmentList - -BeginTransactionStmt: - "BEGIN" - { - $$ = &ast.BeginStmt{} - } -| "START" "TRANSACTION" - { - $$ = &ast.BeginStmt{} - } -| "START" "TRANSACTION" "WITH" "CONSISTENT" "SNAPSHOT" - { - $$ = &ast.BeginStmt{} - } - -BinlogStmt: - "BINLOG" stringLit - { - $$ = &ast.BinlogStmt{Str: $2} - } - -ColumnDefList: - ColumnDef - { - $$ = []*ast.ColumnDef{$1.(*ast.ColumnDef)} - } -| ColumnDefList ',' ColumnDef - { - $$ = append($1.([]*ast.ColumnDef), $3.(*ast.ColumnDef)) - } - -ColumnDef: - ColumnName Type ColumnOptionListOpt - { - $$ = &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType), Options: $3.([]*ast.ColumnOption)} - } - -ColumnName: - Identifier - { - $$ = &ast.ColumnName{Name: model.NewCIStr($1)} - } -| Identifier '.' Identifier - { - $$ = &ast.ColumnName{Table: model.NewCIStr($1), Name: model.NewCIStr($3)} - } -| Identifier '.' Identifier '.' Identifier - { - $$ = &ast.ColumnName{Schema: model.NewCIStr($1), Table: model.NewCIStr($3), Name: model.NewCIStr($5)} - } - -ColumnNameList: - ColumnName - { - $$ = []*ast.ColumnName{$1.(*ast.ColumnName)} - } -| ColumnNameList ',' ColumnName - { - $$ = append($1.([]*ast.ColumnName), $3.(*ast.ColumnName)) - } - -ColumnNameListOpt: - /* EMPTY */ - { - $$ = []*ast.ColumnName{} - } -| ColumnNameList - { - $$ = $1.([]*ast.ColumnName) - } - -ColumnNameListOptWithBrackets: - /* EMPTY */ - { - $$ = []*ast.ColumnName{} - } -| '(' ColumnNameListOpt ')' - { - $$ = $2.([]*ast.ColumnName) - } - -CommitStmt: - "COMMIT" - { - $$ = &ast.CommitStmt{} - } - -PrimaryOpt: - {} -| "PRIMARY" - -ColumnOption: - "NOT" "NULL" - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNotNull} - } -| "NULL" - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNull} - } -| "AUTO_INCREMENT" - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoIncrement} - } -| PrimaryOpt "KEY" - { - // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY - // can also be specified as just KEY when given in a column definition. - // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey} - } -| "UNIQUE" %prec lowerThanKey - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey} - } -| "UNIQUE" "KEY" - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey} - } -| "DEFAULT" DefaultValueExpr - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionDefaultValue, Expr: $2} - } -| "ON" "UPDATE" NowSymOptionFraction - { - nowFunc := &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")} - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionOnUpdate, Expr: nowFunc} - } -| "COMMENT" stringLit - { - $$ = &ast.ColumnOption{Tp: ast.ColumnOptionComment, Expr: ast.NewValueExpr($2)} - } -| "CHECK" '(' Expression ')' - { - // See https://dev.mysql.com/doc/refman/5.7/en/create-table.html - // The CHECK clause is parsed but ignored by all storage engines. - $$ = &ast.ColumnOption{} - } -| GeneratedAlways "AS" '(' Expression ')' VirtualOrStored - { - startOffset := parser.startOffset(&yyS[yypt-2]) - endOffset := parser.endOffset(&yyS[yypt-1]) - expr := $4 - expr.SetText(parser.src[startOffset:endOffset]) - - $$ = &ast.ColumnOption{ - Tp: ast.ColumnOptionGenerated, - Expr: expr, - Stored: $6.(bool), - } - } -| ReferDef - { - $$ = &ast.ColumnOption{ - Tp: ast.ColumnOptionReference, - Refer: $1.(*ast.ReferenceDef), - } - } - -GeneratedAlways: | "GENERATED" "ALWAYS" - -VirtualOrStored: - { - $$ = false - } -| "VIRTUAL" - { - $$ = false - } -| "STORED" - { - $$ = true - } - -ColumnOptionList: - ColumnOption - { - $$ = []*ast.ColumnOption{$1.(*ast.ColumnOption)} - } -| ColumnOptionList ColumnOption - { - $$ = append($1.([]*ast.ColumnOption), $2.(*ast.ColumnOption)) - } - -ColumnOptionListOpt: - { - $$ = []*ast.ColumnOption{} - } -| ColumnOptionList - { - $$ = $1.([]*ast.ColumnOption) - } - -ConstraintElem: - "PRIMARY" "KEY" IndexName IndexTypeOpt '(' IndexColNameList ')' IndexOptionList - { - c := &ast.Constraint{ - Tp: ast.ConstraintPrimaryKey, - Keys: $6.([]*ast.IndexColName), - } - if $8 != nil { - c.Option = $8.(*ast.IndexOption) - } - if $4 != nil { - if c.Option == nil { - c.Option = &ast.IndexOption{} - } - c.Option.Tp = $4.(model.IndexType) - } - $$ = c - } -| "FULLTEXT" KeyOrIndex IndexName '(' IndexColNameList ')' IndexOptionList - { - c := &ast.Constraint{ - Tp: ast.ConstraintFulltext, - Keys: $5.([]*ast.IndexColName), - Name: $3.(string), - } - if $7 != nil { - c.Option = $7.(*ast.IndexOption) - } - $$ = c - } -| KeyOrIndex IndexName IndexTypeOpt '(' IndexColNameList ')' IndexOptionList - { - c := &ast.Constraint{ - Tp: ast.ConstraintIndex, - Keys: $5.([]*ast.IndexColName), - Name: $2.(string), - } - if $7 != nil { - c.Option = $7.(*ast.IndexOption) - } - if $3 != nil { - if c.Option == nil { - c.Option = &ast.IndexOption{} - } - c.Option.Tp = $3.(model.IndexType) - } - $$ = c - } -| "UNIQUE" KeyOrIndexOpt IndexName IndexTypeOpt '(' IndexColNameList ')' IndexOptionList - { - c := &ast.Constraint{ - Tp: ast.ConstraintUniq, - Keys: $6.([]*ast.IndexColName), - Name: $3.(string), - } - if $8 != nil { - c.Option = $8.(*ast.IndexOption) - } - if $4 != nil { - if c.Option == nil { - c.Option = &ast.IndexOption{} - } - c.Option.Tp = $4.(model.IndexType) - } - $$ = c - } -| "FOREIGN" "KEY" IndexName '(' IndexColNameList ')' ReferDef - { - $$ = &ast.Constraint{ - Tp: ast.ConstraintForeignKey, - Keys: $5.([]*ast.IndexColName), - Name: $3.(string), - Refer: $7.(*ast.ReferenceDef), - } - } - -ReferDef: - "REFERENCES" TableName '(' IndexColNameList ')' OnDeleteOpt OnUpdateOpt - { - var onDeleteOpt *ast.OnDeleteOpt - if $6 != nil { - onDeleteOpt = $6.(*ast.OnDeleteOpt) - } - var onUpdateOpt *ast.OnUpdateOpt - if $7 != nil { - onUpdateOpt = $7.(*ast.OnUpdateOpt) - } - $$ = &ast.ReferenceDef{ - Table: $2.(*ast.TableName), - IndexColNames: $4.([]*ast.IndexColName), - OnDelete: onDeleteOpt, - OnUpdate: onUpdateOpt, - } - } - -OnDeleteOpt: - { - $$ = &ast.OnDeleteOpt{} - } %prec lowerThanOn -| "ON" "DELETE" ReferOpt - { - $$ = &ast.OnDeleteOpt{ReferOpt: $3.(ast.ReferOptionType)} - } - -OnUpdateOpt: - { - $$ = &ast.OnUpdateOpt{} - } %prec lowerThanOn -| "ON" "UPDATE" ReferOpt - { - $$ = &ast.OnUpdateOpt{ReferOpt: $3.(ast.ReferOptionType)} - } - -ReferOpt: - "RESTRICT" - { - $$ = ast.ReferOptionRestrict - } -| "CASCADE" - { - $$ = ast.ReferOptionCascade - } -| "SET" "NULL" - { - $$ = ast.ReferOptionSetNull - } -| "NO" "ACTION" - { - $$ = ast.ReferOptionNoAction - } - -/* - * The DEFAULT clause specifies a default value for a column. - * With one exception, the default value must be a constant; - * it cannot be a function or an expression. This means, for example, - * that you cannot set the default for a date column to be the value of - * a function such as NOW() or CURRENT_DATE. The exception is that you - * can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP or DATETIME column. - * - * See http://dev.mysql.com/doc/refman/5.7/en/create-table.html - * https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L6832 - */ -DefaultValueExpr: - NowSymOptionFraction | SignedLiteral - -NowSymOptionFraction: - NowSym - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")} - } -| NowSymFunc '(' ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")} - } -| NowSymFunc '(' NUM ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")} - } - -/* -* See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_localtime -* TODO: Process other three keywords -*/ -NowSymFunc: - "CURRENT_TIMESTAMP" | "LOCALTIME" | "LOCALTIMESTAMP" | builtinNow -NowSym: - "CURRENT_TIMESTAMP" | "LOCALTIME" | "LOCALTIMESTAMP" - - -SignedLiteral: - Literal - { - $$ = ast.NewValueExpr($1) - } -| '+' NumLiteral - { - $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: ast.NewValueExpr($2)} - } -| '-' NumLiteral - { - $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: ast.NewValueExpr($2)} - } - -NumLiteral: - intLit -| floatLit -| decLit - - -CreateIndexStmt: - "CREATE" CreateIndexStmtUnique "INDEX" Identifier IndexTypeOpt "ON" TableName '(' IndexColNameList ')' IndexOptionList LockClauseOpt - { - var indexOption *ast.IndexOption - if $11 != nil { - indexOption = $11.(*ast.IndexOption) - if indexOption.Tp == model.IndexTypeInvalid { - if $5 != nil { - indexOption.Tp = $5.(model.IndexType) - } - } - } else { - indexOption = &ast.IndexOption{} - if $5 != nil { - indexOption.Tp = $5.(model.IndexType) - } - } - $$ = &ast.CreateIndexStmt{ - Unique: $2.(bool), - IndexName: $4, - Table: $7.(*ast.TableName), - IndexColNames: $9.([]*ast.IndexColName), - IndexOption: indexOption, - } - } - -CreateIndexStmtUnique: - { - $$ = false - } -| "UNIQUE" - { - $$ = true - } - -IndexColName: - ColumnName OptFieldLen Order - { - //Order is parsed but just ignored as MySQL did - $$ = &ast.IndexColName{Column: $1.(*ast.ColumnName), Length: $2.(int)} - } - -IndexColNameList: - IndexColName - { - $$ = []*ast.IndexColName{$1.(*ast.IndexColName)} - } -| IndexColNameList ',' IndexColName - { - $$ = append($1.([]*ast.IndexColName), $3.(*ast.IndexColName)) - } - - - -/******************************************************************* - * - * Create Database Statement - * CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name - * [create_specification] ... - * - * create_specification: - * [DEFAULT] CHARACTER SET [=] charset_name - * | [DEFAULT] COLLATE [=] collation_name - *******************************************************************/ -CreateDatabaseStmt: - "CREATE" DatabaseSym IfNotExists DBName DatabaseOptionListOpt - { - $$ = &ast.CreateDatabaseStmt{ - IfNotExists: $3.(bool), - Name: $4.(string), - Options: $5.([]*ast.DatabaseOption), - } - } - -DBName: - Identifier - { - $$ = $1 - } - -DatabaseOption: - DefaultKwdOpt CharsetKw EqOpt CharsetName - { - $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCharset, Value: $4.(string)} - } -| DefaultKwdOpt "COLLATE" EqOpt StringName - { - $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCollate, Value: $4.(string)} - } - -DatabaseOptionListOpt: - { - $$ = []*ast.DatabaseOption{} - } -| DatabaseOptionList - -DatabaseOptionList: - DatabaseOption - { - $$ = []*ast.DatabaseOption{$1.(*ast.DatabaseOption)} - } -| DatabaseOptionList DatabaseOption - { - $$ = append($1.([]*ast.DatabaseOption), $2.(*ast.DatabaseOption)) - } - -/******************************************************************* - * - * Create Table Statement - * - * Example: - * CREATE TABLE Persons - * ( - * P_Id int NOT NULL, - * LastName varchar(255) NOT NULL, - * FirstName varchar(255), - * Address varchar(255), - * City varchar(255), - * PRIMARY KEY (P_Id) - * ) - *******************************************************************/ - -CreateTableStmt: - "CREATE" "TABLE" IfNotExists TableName TableElementListOpt CreateTableOptionListOpt PartitionOpt DuplicateOpt AsOpt CreateTableSelectOpt - { - stmt := $5.(*ast.CreateTableStmt) - stmt.Table = $4.(*ast.TableName) - stmt.IfNotExists = $3.(bool) - stmt.Options = $6.([]*ast.TableOption) - if $7 != nil { - stmt.Partition = $7.(*ast.PartitionOptions) - } - stmt.OnDuplicate = $8.(ast.OnDuplicateCreateTableSelectType) - stmt.Select = $10.(*ast.CreateTableStmt).Select - $$ = stmt - } -| "CREATE" "TABLE" IfNotExists TableName LikeTableWithOrWithoutParen - { - $$ = &ast.CreateTableStmt{ - Table: $4.(*ast.TableName), - ReferTable: $5.(*ast.TableName), - IfNotExists: $3.(bool), - } - } - -DefaultKwdOpt: - {} -| "DEFAULT" - -PartitionOpt: - { - $$ = nil - } -| "PARTITION" "BY" "KEY" '(' ColumnNameList ')' PartitionNumOpt PartitionDefinitionListOpt - { - $$ = nil - } -| "PARTITION" "BY" "HASH" '(' Expression ')' PartitionNumOpt PartitionDefinitionListOpt - { - $$ = nil - } -| "PARTITION" "BY" "RANGE" '(' Expression ')' PartitionNumOpt SubPartitionOpt PartitionDefinitionListOpt - { - var defs []*ast.PartitionDefinition - if $9 != nil { - defs = $9.([]*ast.PartitionDefinition) - } - $$ = &ast.PartitionOptions{ - Tp: model.PartitionTypeRange, - Expr: $5.(ast.ExprNode), - Definitions: defs, - } - } -| "PARTITION" "BY" "RANGE" "COLUMNS" '(' ColumnNameList ')' PartitionNumOpt PartitionDefinitionListOpt - { - var defs []*ast.PartitionDefinition - if $9 != nil { - defs = $9.([]*ast.PartitionDefinition) - } - $$ = &ast.PartitionOptions{ - Tp: model.PartitionTypeRange, - ColumnNames: $6.([]*ast.ColumnName), - Definitions: defs, - } - } - -SubPartitionOpt: - {} -| "SUBPARTITION" "BY" "HASH" '(' Expression ')' SubPartitionNumOpt - {} -| "SUBPARTITION" "BY" "KEY" '(' ColumnNameList ')' SubPartitionNumOpt - {} - -SubPartitionNumOpt: - {} -| "SUBPARTITIONS" NUM - {} - -PartitionNumOpt: - {} -| "PARTITIONS" NUM - {} - -PartitionDefinitionListOpt: - /* empty */ %prec lowerThanCreateTableSelect - { - $$ = nil - } -| '(' PartitionDefinitionList ')' - { - $$ = $2.([]*ast.PartitionDefinition) - } - -PartitionDefinitionList: - PartitionDefinition - { - $$ = []*ast.PartitionDefinition{$1.(*ast.PartitionDefinition)} - } -| PartitionDefinitionList ',' PartitionDefinition - { - $$ = append($1.([]*ast.PartitionDefinition), $3.(*ast.PartitionDefinition)) - } - -PartitionDefinition: - "PARTITION" Identifier PartDefValuesOpt PartDefOptionsOpt - { - partDef := &ast.PartitionDefinition{ - Name: model.NewCIStr($2), - } - switch $3.(type) { - case []ast.ExprNode: - partDef.LessThan = $3.([]ast.ExprNode) - case ast.ExprNode: - partDef.LessThan = make([]ast.ExprNode, 1) - partDef.LessThan[0] = $3.(ast.ExprNode) - } - - if comment, ok := $4.(string); ok { - partDef.Comment = comment - } - $$ = partDef - } - -PartDefOptionsOpt: - { - $$ = nil - } -| PartDefOptionList - { - $$ = $1 - } - -PartDefOptionList: - PartDefOption - { - $$ = $1 - } -| PartDefOptionList PartDefOption - { - if $1 != nil { - $$ = $1 - } else { - $$ = $2 - } - } - -PartDefOption: - "COMMENT" EqOpt stringLit - { - $$ = $3 - } -| "ENGINE" EqOpt Identifier - { - $$ = nil - } -| "TABLESPACE" EqOpt Identifier - { - $$ = nil - } - - -PartDefValuesOpt: - { - $$ = nil - } -| "VALUES" "LESS" "THAN" "MAXVALUE" - { - $$ = &ast.MaxValueExpr{} - } -| "VALUES" "LESS" "THAN" '(' MaxValueOrExpressionList ')' - { - $$ = $5 - } - -DuplicateOpt: - { - $$ = ast.OnDuplicateCreateTableSelectError - } -| "IGNORE" - { - $$ = ast.OnDuplicateCreateTableSelectIgnore - } -| "REPLACE" - { - $$ = ast.OnDuplicateCreateTableSelectReplace - } - -AsOpt: - {} -| "AS" - {} - -CreateTableSelectOpt: - /* empty */ - { - $$ = &ast.CreateTableStmt{} - } -| - SelectStmt - { - $$ = &ast.CreateTableStmt{Select: $1} - } -| - UnionStmt - { - $$ = &ast.CreateTableStmt{Select: $1} - } -| - SubSelect %prec createTableSelect - // TODO: We may need better solution as issue #320. - { - $$ = &ast.CreateTableStmt{Select: $1} - } - -LikeTableWithOrWithoutParen: - "LIKE" TableName - { - $$ = $2 - } -| - '(' "LIKE" TableName ')' - { - $$ = $3 - } - -/******************************************************************* - * - * Create View Statement - * - * Example: - * CREATE VIEW OR REPLACE ALGORITHM = MERGE DEFINER="root@localhost" SQL SECURITY = definer view_name (col1,col2) - * as select Col1,Col2 from table WITH LOCAL CHECK OPTION - *******************************************************************/ -CreateViewStmt: - "CREATE" OrReplace ViewAlgorithm ViewDefiner ViewSQLSecurity "VIEW" ViewName ViewFieldList "AS" SelectStmt ViewCheckOption - { - startOffset := parser.startOffset(&yyS[yypt-1]) - selStmt := $10.(*ast.SelectStmt) - selStmt.SetText(string(parser.src[startOffset:])) - x := &ast.CreateViewStmt { - OrReplace: $2.(bool), - ViewName: $7.(*ast.TableName), - Select: selStmt, - } - if $8 != nil{ - x.Cols = $8.([]model.CIStr) - } - $$ = x - } - -OrReplace: - { - $$ = false - } -| "OR" "REPLACE" - { - $$ = true - } - -ViewAlgorithm: - /* EMPTY */ - { - $$ = "UNDEFINED" - } -| "ALGORITHM" "=" "UNDEFINED" - { - $$ = strings.ToUpper($3) - } -| "ALGORITHM" "=" "MERGE" - { - $$ = strings.ToUpper($3) - } -| "ALGORITHM" "=" "TEMPTABLE" - { - $$ = strings.ToUpper($3) - } - -ViewDefiner: - /* EMPTY */ - { - $$ = nil - } -| "DEFINER" "=" Username - { - $$ = $3 - } - -ViewSQLSecurity: - /* EMPTY */ - { - $$ = "DEFINER" - } -| "SQL" "SECURITY" "DEFINER" - { - $$ = $3 - } -| "SQL" "SECURITY" "INVOKER" - { - $$ = $3 - } - -ViewName: - TableName - { - $$ = $1.(*ast.TableName) - } - -ViewFieldList: - /* Empty */ - { - $$ = nil - } -| '(' ColumnList ')' - { - $$ = $2.([]model.CIStr) - } - -ColumnList: - Identifier - { - $$ = []model.CIStr{model.NewCIStr($1)} - } -| ColumnList ',' Identifier - { - $$ = append($1.([]model.CIStr), model.NewCIStr($3)) - } - -ViewCheckOption: - /* EMPTY */ - { - $$ = nil - } -| "WITH" "CASCADED" "CHECK" "OPTION" - { - $$ = $2 - } -| "WITH" "LOCAL" "CHECK" "OPTION" - { - $$ = $2 - } - -/****************************************************************** - * Do statement - * See https://dev.mysql.com/doc/refman/5.7/en/do.html - ******************************************************************/ -DoStmt: - "DO" ExpressionList - { - $$ = &ast.DoStmt { - Exprs: $2.([]ast.ExprNode), - } - } - -/******************************************************************* - * - * Delete Statement - * - *******************************************************************/ -DeleteFromStmt: - "DELETE" TableOptimizerHints PriorityOpt QuickOptional IgnoreOptional "FROM" TableName IndexHintListOpt WhereClauseOptional OrderByOptional LimitClause - { - // Single Table - tn := $7.(*ast.TableName) - tn.IndexHints = $8.([]*ast.IndexHint) - join := &ast.Join{Left: &ast.TableSource{Source: tn}, Right: nil} - x := &ast.DeleteStmt{ - TableRefs: &ast.TableRefsClause{TableRefs: join}, - Priority: $3.(mysql.PriorityEnum), - Quick: $4.(bool), - IgnoreErr: $5.(bool), - } - if $9 != nil { - x.Where = $9.(ast.ExprNode) - } - if $10 != nil { - x.Order = $10.(*ast.OrderByClause) - } - if $11 != nil { - x.Limit = $11.(*ast.Limit) - } - - $$ = x - } -| "DELETE" TableOptimizerHints PriorityOpt QuickOptional IgnoreOptional TableNameList "FROM" TableRefs WhereClauseOptional - { - // Multiple Table - x := &ast.DeleteStmt{ - Priority: $3.(mysql.PriorityEnum), - Quick: $4.(bool), - IgnoreErr: $5.(bool), - IsMultiTable: true, - BeforeFrom: true, - Tables: &ast.DeleteTableList{Tables: $6.([]*ast.TableName)}, - TableRefs: &ast.TableRefsClause{TableRefs: $8.(*ast.Join)}, - } - if $2 != nil { - x.TableHints = $2.([]*ast.TableOptimizerHint) - } - if $9 != nil { - x.Where = $9.(ast.ExprNode) - } - $$ = x - } - -| "DELETE" TableOptimizerHints PriorityOpt QuickOptional IgnoreOptional "FROM" TableNameList "USING" TableRefs WhereClauseOptional - { - // Multiple Table - x := &ast.DeleteStmt{ - Priority: $3.(mysql.PriorityEnum), - Quick: $4.(bool), - IgnoreErr: $5.(bool), - IsMultiTable: true, - Tables: &ast.DeleteTableList{Tables: $7.([]*ast.TableName)}, - TableRefs: &ast.TableRefsClause{TableRefs: $9.(*ast.Join)}, - } - if $2 != nil { - x.TableHints = $2.([]*ast.TableOptimizerHint) - } - if $10 != nil { - x.Where = $10.(ast.ExprNode) - } - $$ = x - } - -DatabaseSym: -"DATABASE" - -DropDatabaseStmt: - "DROP" DatabaseSym IfExists DBName - { - $$ = &ast.DropDatabaseStmt{IfExists: $3.(bool), Name: $4.(string)} - } - -DropIndexStmt: - "DROP" "INDEX" IfExists Identifier "ON" TableName - { - $$ = &ast.DropIndexStmt{IfExists: $3.(bool), IndexName: $4, Table: $6.(*ast.TableName)} - } - -DropTableStmt: - "DROP" TableOrTables TableNameList RestrictOrCascadeOpt - { - $$ = &ast.DropTableStmt{Tables: $3.([]*ast.TableName)} - } -| "DROP" TableOrTables "IF" "EXISTS" TableNameList RestrictOrCascadeOpt - { - $$ = &ast.DropTableStmt{IfExists: true, Tables: $5.([]*ast.TableName)} - } - -DropViewStmt: - "DROP" "VIEW" "IF" "EXISTS" TableNameList - { - $$ = &ast.DoStmt{} - } - -DropUserStmt: - "DROP" "USER" UsernameList - { - $$ = &ast.DropUserStmt{IfExists: false, UserList: $3.([]*auth.UserIdentity)} - } -| "DROP" "USER" "IF" "EXISTS" UsernameList - { - $$ = &ast.DropUserStmt{IfExists: true, UserList: $5.([]*auth.UserIdentity)} - } - -DropStatsStmt: - "DROP" "STATS" TableName - { - $$ = &ast.DropStatsStmt{Table: $3.(*ast.TableName)} - } - -RestrictOrCascadeOpt: - {} -| "RESTRICT" -| "CASCADE" - -TableOrTables: - "TABLE" -| "TABLES" - -EqOpt: - {} -| eq - -EmptyStmt: - /* EMPTY */ - { - $$ = nil - } - -TraceStmt: - "TRACE" TraceableStmt - { - $$ = &ast.TraceStmt{ - Stmt: $2, - Format: "row", - } - } - -ExplainSym: -"EXPLAIN" | "DESCRIBE" | "DESC" - -ExplainStmt: - ExplainSym TableName - { - $$ = &ast.ExplainStmt{ - Stmt: &ast.ShowStmt{ - Tp: ast.ShowColumns, - Table: $2.(*ast.TableName), - }, - } - } -| ExplainSym TableName ColumnName - { - $$ = &ast.ExplainStmt{ - Stmt: &ast.ShowStmt{ - Tp: ast.ShowColumns, - Table: $2.(*ast.TableName), - Column: $3.(*ast.ColumnName), - }, - } - } -| ExplainSym ExplainableStmt - { - $$ = &ast.ExplainStmt{ - Stmt: $2, - Format: "row", - } - } -| ExplainSym "FORMAT" "=" stringLit ExplainableStmt - { - $$ = &ast.ExplainStmt{ - Stmt: $5, - Format: $4, - } - } -| ExplainSym "ANALYZE" ExplainableStmt - { - $$ = &ast.ExplainStmt { - Stmt: $3, - Format: "row", - Analyze: true, - } - } - -LengthNum: - NUM - { - $$ = getUint64FromNUM($1) - } - -NUM: - intLit - -Expression: - singleAtIdentifier assignmentEq Expression %prec assignmentEq - { - v := $1 - v = strings.TrimPrefix(v, "@") - $$ = &ast.VariableExpr{ - Name: v, - IsGlobal: false, - IsSystem: false, - Value: $3, - } - } -| Expression logOr Expression %prec pipes - { - $$ = &ast.BinaryOperationExpr{Op: opcode.LogicOr, L: $1, R: $3} - } -| Expression "XOR" Expression %prec xor - { - $$ = &ast.BinaryOperationExpr{Op: opcode.LogicXor, L: $1, R: $3} - } -| Expression logAnd Expression %prec andand - { - $$ = &ast.BinaryOperationExpr{Op: opcode.LogicAnd, L: $1, R: $3} - } -| "NOT" Expression %prec not - { - expr, ok := $2.(*ast.ExistsSubqueryExpr) - if ok { - expr.Not = true - $$ = $2 - } else { - $$ = &ast.UnaryOperationExpr{Op: opcode.Not, V: $2} - } - } -| BoolPri IsOrNotOp trueKwd %prec is - { - $$ = &ast.IsTruthExpr{Expr:$1, Not: !$2.(bool), True: int64(1)} - } -| BoolPri IsOrNotOp falseKwd %prec is - { - $$ = &ast.IsTruthExpr{Expr:$1, Not: !$2.(bool), True: int64(0)} - } -| BoolPri IsOrNotOp "UNKNOWN" %prec is - { - /* https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_is */ - $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)} - } -| BoolPri - -MaxValueOrExpression: - "MAXVALUE" - { - $$ = &ast.MaxValueExpr{} - } -| Expression - { - $$ = $1 - } - - -logOr: - pipesAsOr -| "OR" - -logAnd: -"&&" | "AND" - -ExpressionList: - Expression - { - $$ = []ast.ExprNode{$1} - } -| ExpressionList ',' Expression - { - $$ = append($1.([]ast.ExprNode), $3) - } - -MaxValueOrExpressionList: - MaxValueOrExpression - { - $$ = []ast.ExprNode{$1} -} -| MaxValueOrExpressionList ',' MaxValueOrExpression -{ - $$ = append($1.([]ast.ExprNode), $3) - } - - -ExpressionListOpt: - { - $$ = []ast.ExprNode{} - } -| ExpressionList - -FuncDatetimePrecListOpt: - { - $$ = []ast.ExprNode{} - } -| FuncDatetimePrecList - { - $$ = $1 - } - -FuncDatetimePrecList: - intLit - { - expr := ast.NewValueExpr($1) - $$ = []ast.ExprNode{expr} - } - -BoolPri: - BoolPri IsOrNotOp "NULL" %prec is - { - $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)} - } -| BoolPri CompareOp PredicateExpr %prec eq - { - $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: $3} - } -| BoolPri CompareOp AnyOrAll SubSelect %prec eq - { - sq := $4.(*ast.SubqueryExpr) - sq.MultiRows = true - $$ = &ast.CompareSubqueryExpr{Op: $2.(opcode.Op), L: $1, R: sq, All: $3.(bool)} - } -| BoolPri CompareOp singleAtIdentifier assignmentEq PredicateExpr %prec assignmentEq - { - v := $3 - v = strings.TrimPrefix(v, "@") - variable := &ast.VariableExpr{ - Name: v, - IsGlobal: false, - IsSystem: false, - Value: $5, - } - $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: variable} - } -| PredicateExpr - -CompareOp: - ">=" - { - $$ = opcode.GE - } -| '>' - { - $$ = opcode.GT - } -| "<=" - { - $$ = opcode.LE - } -| '<' - { - $$ = opcode.LT - } -| "!=" - { - $$ = opcode.NE - } -| "<>" - { - $$ = opcode.NE - } -| "=" - { - $$ = opcode.EQ - } -| "<=>" - { - $$ = opcode.NullEQ - } - -BetweenOrNotOp: - "BETWEEN" - { - $$ = true - } -| "NOT" "BETWEEN" - { - $$ = false - } - -IsOrNotOp: - "IS" - { - $$ = true - } -| "IS" "NOT" - { - $$ = false - } - -InOrNotOp: - "IN" - { - $$ = true - } -| "NOT" "IN" - { - $$ = false - } - -LikeOrNotOp: - "LIKE" - { - $$ = true - } -| "NOT" "LIKE" - { - $$ = false - } - -RegexpOrNotOp: - RegexpSym - { - $$ = true - } -| "NOT" RegexpSym - { - $$ = false - } - -AnyOrAll: - "ANY" - { - $$ = false - } -| "SOME" - { - $$ = false - } -| "ALL" - { - $$ = true - } - -PredicateExpr: - BitExpr InOrNotOp '(' ExpressionList ')' - { - $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), List: $4.([]ast.ExprNode)} - } -| BitExpr InOrNotOp SubSelect - { - sq := $3.(*ast.SubqueryExpr) - sq.MultiRows = true - $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), Sel: sq} - } -| BitExpr BetweenOrNotOp BitExpr "AND" PredicateExpr - { - $$ = &ast.BetweenExpr{ - Expr: $1, - Left: $3, - Right: $5, - Not: !$2.(bool), - } - } -| BitExpr LikeOrNotOp SimpleExpr LikeEscapeOpt - { - escape := $4.(string) - if len(escape) > 1 { - yylex.Errorf("Incorrect arguments %s to ESCAPE", escape) - return 1 - } else if len(escape) == 0 { - escape = "\\" - } - $$ = &ast.PatternLikeExpr{ - Expr: $1, - Pattern: $3, - Not: !$2.(bool), - Escape: escape[0], - } - } -| BitExpr RegexpOrNotOp SimpleExpr - { - $$ = &ast.PatternRegexpExpr{Expr: $1, Pattern: $3, Not: !$2.(bool)} - } -| BitExpr - -RegexpSym: -"REGEXP" | "RLIKE" - -LikeEscapeOpt: - %prec empty - { - $$ = "\\" - } -| "ESCAPE" stringLit - { - $$ = $2 - } - -Field: - '*' - { - $$ = &ast.SelectField{WildCard: &ast.WildCardField{}} - } -| Identifier '.' '*' - { - wildCard := &ast.WildCardField{Table: model.NewCIStr($1)} - $$ = &ast.SelectField{WildCard: wildCard} - } -| Identifier '.' Identifier '.' '*' - { - wildCard := &ast.WildCardField{Schema: model.NewCIStr($1), Table: model.NewCIStr($3)} - $$ = &ast.SelectField{WildCard: wildCard} - } -| Expression FieldAsNameOpt - { - expr := $1 - asName := $2.(string) - $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)} - } -| '{' Identifier Expression '}' FieldAsNameOpt - { - /* - * ODBC escape syntax. - * See https://dev.mysql.com/doc/refman/5.7/en/expressions.html - */ - expr := $3 - asName := $5.(string) - $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)} - } - -FieldAsNameOpt: - /* EMPTY */ - { - $$ = "" - } -| FieldAsName - { - $$ = $1 - } - -FieldAsName: - Identifier - { - $$ = $1 - } -| "AS" Identifier - { - $$ = $2 - } -| stringLit - { - $$ = $1 - } -| "AS" stringLit - { - $$ = $2 - } - -FieldList: - Field - { - field := $1.(*ast.SelectField) - field.Offset = parser.startOffset(&yyS[yypt]) - $$ = []*ast.SelectField{field} - } -| FieldList ',' Field - { - - fl := $1.([]*ast.SelectField) - last := fl[len(fl)-1] - if last.Expr != nil && last.AsName.O == "" { - lastEnd := parser.endOffset(&yyS[yypt-1]) - last.SetText(parser.src[last.Offset:lastEnd]) - } - newField := $3.(*ast.SelectField) - newField.Offset = parser.startOffset(&yyS[yypt]) - $$ = append(fl, newField) - } - -GroupByClause: - "GROUP" "BY" ByList - { - $$ = &ast.GroupByClause{Items: $3.([]*ast.ByItem)} - } - -HavingClause: - { - $$ = nil - } -| "HAVING" Expression - { - $$ = &ast.HavingClause{Expr: $2} - } - -IfExists: - { - $$ = false - } -| "IF" "EXISTS" - { - $$ = true - } - -IfNotExists: - { - $$ = false - } -| "IF" "NOT" "EXISTS" - { - $$ = true - } - - -IgnoreOptional: - { - $$ = false - } -| "IGNORE" - { - $$ = true - } - -IndexName: - { - $$ = "" - } -| Identifier - { - //"index name" - $$ = $1 - } - -IndexOptionList: - { - $$ = nil - } -| IndexOptionList IndexOption - { - // Merge the options - if $1 == nil { - $$ = $2 - } else { - opt1 := $1.(*ast.IndexOption) - opt2 := $2.(*ast.IndexOption) - if len(opt2.Comment) > 0 { - opt1.Comment = opt2.Comment - } else if opt2.Tp != 0 { - opt1.Tp = opt2.Tp - } - $$ = opt1 - } - } - - -IndexOption: - "KEY_BLOCK_SIZE" EqOpt LengthNum - { - $$ = &ast.IndexOption{ - // TODO bug should be fix here! - // KeyBlockSize: $1.(uint64), - } - } -| IndexType - { - $$ = &ast.IndexOption { - Tp: $1.(model.IndexType), - } - } -| "COMMENT" stringLit - { - $$ = &ast.IndexOption { - Comment: $2, - } - } - -IndexType: - "USING" "BTREE" - { - $$ = model.IndexTypeBtree - } -| "USING" "HASH" - { - $$ = model.IndexTypeHash - } - -IndexTypeOpt: - { - $$ = nil - } -| IndexType - { - $$ = $1 - } - -/**********************************Identifier********************************************/ -Identifier: -identifier | UnReservedKeyword | NotKeywordToken | TiDBKeyword - -UnReservedKeyword: - "ACTION" | "ASCII" | "AUTO_INCREMENT" | "AFTER" | "ALWAYS" | "AVG" | "BEGIN" | "BIT" | "BOOL" | "BOOLEAN" | "BTREE" | "BYTE" | "CLEANUP" | "CHARSET" -| "COLUMNS" | "COMMIT" | "COMPACT" | "COMPRESSED" | "CONSISTENT" | "DATA" | "DATE" %prec lowerThanStringLitToken| "DATETIME" | "DAY" | "DEALLOCATE" | "DO" | "DUPLICATE" -| "DYNAMIC"| "END" | "ENGINE" | "ENGINES" | "ENUM" | "ERRORS" | "ESCAPE" | "EXECUTE" | "FIELDS" | "FIRST" | "FIXED" | "FLUSH" | "FORMAT" | "FULL" |"GLOBAL" -| "HASH" | "HOUR" | "LESS" | "LOCAL" | "NAMES" | "OFFSET" | "PASSWORD" %prec lowerThanEq | "PREPARE" | "QUICK" | "REDUNDANT" -| "ROLLBACK" | "SESSION" | "SIGNED" | "SNAPSHOT" | "START" | "STATUS" | "SUBPARTITIONS" | "SUBPARTITION" | "TABLES" | "TABLESPACE" | "TEXT" | "THAN" | "TIME" %prec lowerThanStringLitToken -| "TIMESTAMP" %prec lowerThanStringLitToken | "TRACE" | "TRANSACTION" | "TRUNCATE" | "UNKNOWN" | "VALUE" | "WARNINGS" | "YEAR" | "MODE" | "WEEK" | "ANY" | "SOME" | "USER" | "IDENTIFIED" -| "COLLATION" | "COMMENT" | "AVG_ROW_LENGTH" | "CONNECTION" | "CHECKSUM" | "COMPRESSION" | "KEY_BLOCK_SIZE" | "MASTER" | "MAX_ROWS" -| "MIN_ROWS" | "NATIONAL" | "ROW" | "ROW_FORMAT" | "QUARTER" | "GRANTS" | "TRIGGERS" | "DELAY_KEY_WRITE" | "ISOLATION" | "JSON" -| "REPEATABLE" | "COMMITTED" | "UNCOMMITTED" | "ONLY" | "SERIALIZABLE" | "LEVEL" | "VARIABLES" | "SQL_CACHE" | "INDEXES" | "PROCESSLIST" -| "SQL_NO_CACHE" | "DISABLE" | "ENABLE" | "REVERSE" | "PRIVILEGES" | "NO" | "BINLOG" | "FUNCTION" | "VIEW" | "MODIFY" | "EVENTS" | "PARTITIONS" -| "NONE" | "SUPER" | "EXCLUSIVE" | "STATS_PERSISTENT" | "ROW_COUNT" | "COALESCE" | "MONTH" | "PROCESS" | "PROFILES" -| "MICROSECOND" | "MINUTE" | "PLUGINS" | "QUERY" | "QUERIES" | "SECOND" | "SEPARATOR" | "SHARE" | "SHARED" | "SLOW" | "MAX_CONNECTIONS_PER_HOUR" | "MAX_QUERIES_PER_HOUR" | "MAX_UPDATES_PER_HOUR" -| "MAX_USER_CONNECTIONS" | "REPLICATION" | "CLIENT" | "SLAVE" | "RELOAD" | "TEMPORARY" | "ROUTINE" | "EVENT" | "ALGORITHM" | "DEFINER" | "INVOKER" | "MERGE" | "TEMPTABLE" | "UNDEFINED" | "SECURITY" | "CASCADED" | "RECOVER" - - - -TiDBKeyword: -"ADMIN" | "BUCKETS" | "CANCEL" | "DDL" | "JOBS" | "JOB" | "STATS" | "STATS_META" | "STATS_HISTOGRAMS" | "STATS_BUCKETS" | "STATS_HEALTHY" | "TIDB" | "TIDB_HJ" | "TIDB_SMJ" | "TIDB_INLJ" - -NotKeywordToken: - "ADDDATE" | "BIT_AND" | "BIT_OR" | "BIT_XOR" | "CAST" | "COPY" | "COUNT" | "CURTIME" | "DATE_ADD" | "DATE_SUB" | "EXTRACT" | "GET_FORMAT" | "GROUP_CONCAT" | "INPLACE" | "INTERNAL" -|"MIN" | "MAX" | "MAX_EXECUTION_TIME" | "NOW" | "RECENT" | "POSITION" | "SUBDATE" | "SUBSTRING" | "SUM" | "TIMESTAMPADD" | "TIMESTAMPDIFF" | "TOP" | "TRIM" - -/************************************************************************************ - * - * Insert Statements - * - * TODO: support PARTITION - **********************************************************************************/ -InsertIntoStmt: - "INSERT" PriorityOpt IgnoreOptional IntoOpt TableName InsertValues OnDuplicateKeyUpdate - { - x := $6.(*ast.InsertStmt) - x.Priority = $2.(mysql.PriorityEnum) - x.IgnoreErr = $3.(bool) - // Wraps many layers here so that it can be processed the same way as select statement. - ts := &ast.TableSource{Source: $5.(*ast.TableName)} - x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}} - if $7 != nil { - x.OnDuplicate = $7.([]*ast.Assignment) - } - $$ = x - } - -IntoOpt: - {} -| "INTO" - -InsertValues: - '(' ColumnNameListOpt ')' ValueSym ValuesList - { - $$ = &ast.InsertStmt{ - Columns: $2.([]*ast.ColumnName), - Lists: $5.([][]ast.ExprNode), - } - } -| '(' ColumnNameListOpt ')' SelectStmt - { - $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(*ast.SelectStmt)} - } -| '(' ColumnNameListOpt ')' '(' SelectStmt ')' - { - $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $5.(*ast.SelectStmt)} - } -| '(' ColumnNameListOpt ')' UnionStmt - { - $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(*ast.UnionStmt)} - } -| ValueSym ValuesList %prec insertValues - { - $$ = &ast.InsertStmt{Lists: $2.([][]ast.ExprNode)} - } -| '(' SelectStmt ')' - { - $$ = &ast.InsertStmt{Select: $2.(*ast.SelectStmt)} - } -| SelectStmt - { - $$ = &ast.InsertStmt{Select: $1.(*ast.SelectStmt)} - } -| UnionStmt - { - $$ = &ast.InsertStmt{Select: $1.(*ast.UnionStmt)} - } -| "SET" ColumnSetValueList - { - $$ = &ast.InsertStmt{Setlist: $2.([]*ast.Assignment)} - } - -ValueSym: -"VALUE" | "VALUES" - -ValuesList: - RowValue - { - $$ = [][]ast.ExprNode{$1.([]ast.ExprNode)} - } -| ValuesList ',' RowValue - { - $$ = append($1.([][]ast.ExprNode), $3.([]ast.ExprNode)) - } - -RowValue: - '(' ValuesOpt ')' - { - $$ = $2 - } - -ValuesOpt: - { - $$ = []ast.ExprNode{} - } -| Values - -Values: - Values ',' ExprOrDefault - { - $$ = append($1.([]ast.ExprNode), $3) - } -| ExprOrDefault - { - $$ = []ast.ExprNode{$1} - } - -ExprOrDefault: - Expression -| "DEFAULT" - { - $$ = &ast.DefaultExpr{} - } - -ColumnSetValue: - ColumnName eq Expression - { - $$ = &ast.Assignment{ - Column: $1.(*ast.ColumnName), - Expr: $3, - } - } - -ColumnSetValueList: - { - $$ = []*ast.Assignment{} - } -| ColumnSetValue - { - $$ = []*ast.Assignment{$1.(*ast.Assignment)} - } -| ColumnSetValueList ',' ColumnSetValue - { - $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment)) - } - -/* - * ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... - * See https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html - */ -OnDuplicateKeyUpdate: - { - $$ = nil - } -| "ON" "DUPLICATE" "KEY" "UPDATE" AssignmentList - { - $$ = $5 - } - -/***********************************Insert Statements END************************************/ - -/************************************************************************************ - * Replace Statements - * See https://dev.mysql.com/doc/refman/5.7/en/replace.html - * - * TODO: support PARTITION - **********************************************************************************/ -ReplaceIntoStmt: - "REPLACE" PriorityOpt IntoOpt TableName InsertValues - { - x := $5.(*ast.InsertStmt) - x.IsReplace = true - x.Priority = $2.(mysql.PriorityEnum) - ts := &ast.TableSource{Source: $4.(*ast.TableName)} - x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}} - $$ = x - } - -/***********************************Replace Statements END************************************/ - -ODBCDateTimeType: - "d" - { - $$ = ast.DateLiteral - } -| "t" - { - $$ = ast.TimeLiteral - } -| "ts" - { - $$ = ast.TimestampLiteral - } - -Literal: - "FALSE" - { - $$ = ast.NewValueExpr(false) - } -| "NULL" - { - $$ = ast.NewValueExpr(nil) - } -| "TRUE" - { - $$ = ast.NewValueExpr(true) - } -| floatLit - { - $$ = ast.NewValueExpr($1) - } -| decLit - { - $$ = ast.NewValueExpr($1) - } -| intLit - { - $$ = ast.NewValueExpr($1) - } -| StringLiteral %prec lowerThanStringLitToken - { - $$ = $1 - } -| "UNDERSCORE_CHARSET" stringLit - { - // See https://dev.mysql.com/doc/refman/5.7/en/charset-literal.html - co, err := charset.GetDefaultCollation($1) - if err != nil { - yylex.Errorf("Get collation error for charset: %s", $1) - return 1 - } - expr := ast.NewValueExpr($2) - tp := expr.GetType() - tp.Charset = $1 - tp.Collate = co - if tp.Collate == charset.CollationBin { - tp.Flag |= mysql.BinaryFlag - } - $$ = expr - } -| hexLit - { - $$ = ast.NewValueExpr($1) - } -| bitLit - { - $$ = ast.NewValueExpr($1) - } - -StringLiteral: - stringLit - { - expr := ast.NewValueExpr($1) - $$ = expr - } -| StringLiteral stringLit - { - valExpr := $1.(ast.ValueExpr) - strLit := valExpr.GetString() - expr := ast.NewValueExpr(strLit+$2) - // Fix #4239, use first string literal as projection name. - if valExpr.GetProjectionOffset() >= 0 { - expr.SetProjectionOffset(valExpr.GetProjectionOffset()) - } else { - expr.SetProjectionOffset(len(strLit)) - } - $$ = expr - } - - -OrderBy: - "ORDER" "BY" ByList - { - $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)} - } - -ByList: - ByItem - { - $$ = []*ast.ByItem{$1.(*ast.ByItem)} - } -| ByList ',' ByItem - { - $$ = append($1.([]*ast.ByItem), $3.(*ast.ByItem)) - } - -ByItem: - Expression Order - { - expr := $1 - valueExpr, ok := expr.(ast.ValueExpr) - if ok { - position, isPosition := valueExpr.GetValue().(int64) - if isPosition { - expr = &ast.PositionExpr{N: int(position)} - } - } - $$ = &ast.ByItem{Expr: expr, Desc: $2.(bool)} - } - -Order: - /* EMPTY */ - { - $$ = false // ASC by default - } -| "ASC" - { - $$ = false - } -| "DESC" - { - $$ = true - } - -OrderByOptional: - { - $$ = nil - } -| OrderBy - { - $$ = $1 - } - -BitExpr: - BitExpr '|' BitExpr %prec '|' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Or, L: $1, R: $3} - } -| BitExpr '&' BitExpr %prec '&' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.And, L: $1, R: $3} - } -| BitExpr "<<" BitExpr %prec lsh - { - $$ = &ast.BinaryOperationExpr{Op: opcode.LeftShift, L: $1, R: $3} - } -| BitExpr ">>" BitExpr %prec rsh - { - $$ = &ast.BinaryOperationExpr{Op: opcode.RightShift, L: $1, R: $3} - } -| BitExpr '+' BitExpr %prec '+' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Plus, L: $1, R: $3} - } -| BitExpr '-' BitExpr %prec '-' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Minus, L: $1, R: $3} - } -| BitExpr '+' "INTERVAL" Expression TimeUnit %prec '+' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr("DATE_ADD"), - Args: []ast.ExprNode{ - $1, - $4, - ast.NewValueExpr($5), - }, - } - } -| BitExpr '-' "INTERVAL" Expression TimeUnit %prec '+' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr("DATE_SUB"), - Args: []ast.ExprNode{ - $1, - $4, - ast.NewValueExpr($5), - }, - } - } -| BitExpr '*' BitExpr %prec '*' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Mul, L: $1, R: $3} - } -| BitExpr '/' BitExpr %prec '/' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Div, L: $1, R: $3} - } -| BitExpr '%' BitExpr %prec '%' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3} - } -| BitExpr "DIV" BitExpr %prec div - { - $$ = &ast.BinaryOperationExpr{Op: opcode.IntDiv, L: $1, R: $3} - } -| BitExpr "MOD" BitExpr %prec mod - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3} - } -| BitExpr '^' BitExpr - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Xor, L: $1, R: $3} - } -| SimpleExpr - -SimpleIdent: - Identifier - { - $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ - Name: model.NewCIStr($1), - }} - } -| Identifier '.' Identifier - { - $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ - Table: model.NewCIStr($1), - Name: model.NewCIStr($3), - }} - } -| '.' Identifier '.' Identifier - { - $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ - Table: model.NewCIStr($2), - Name: model.NewCIStr($4), - }} - } -| Identifier '.' Identifier '.' Identifier - { - $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ - Schema: model.NewCIStr($1), - Table: model.NewCIStr($3), - Name: model.NewCIStr($5), - }} - } - -SimpleExpr: - SimpleIdent -| FunctionCallKeyword -| FunctionCallNonKeyword -| FunctionCallGeneric -| SimpleExpr "COLLATE" StringName %prec neg - { - // TODO: Create a builtin function hold expr and collation. When do evaluation, convert expr result using the collation. - $$ = $1 - } -| Literal -| paramMarker - { - $$ = ast.NewParamMarkerExpr(yyS[yypt].offset) - } -| Variable -| SumExpr -| '!' SimpleExpr %prec neg - { - $$ = &ast.UnaryOperationExpr{Op: opcode.Not, V: $2} - } -| '~' SimpleExpr %prec neg - { - $$ = &ast.UnaryOperationExpr{Op: opcode.BitNeg, V: $2} - } -| '-' SimpleExpr %prec neg - { - $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: $2} - } -| '+' SimpleExpr %prec neg - { - $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: $2} - } -| SimpleExpr pipes SimpleExpr - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.Concat), Args: []ast.ExprNode{$1, $3}} - } -| not2 SimpleExpr %prec neg - { - $$ = &ast.UnaryOperationExpr{Op: opcode.Not, V: $2} - } -| SubSelect -| '(' Expression ')' { - startOffset := parser.startOffset(&yyS[yypt-1]) - endOffset := parser.endOffset(&yyS[yypt]) - expr := $2 - expr.SetText(parser.src[startOffset:endOffset]) - $$ = &ast.ParenthesesExpr{Expr: expr} - } -| '(' ExpressionList ',' Expression ')' - { - values := append($2.([]ast.ExprNode), $4) - $$ = &ast.RowExpr{Values: values} - } -| "ROW" '(' ExpressionList ',' Expression ')' - { - values := append($3.([]ast.ExprNode), $5) - $$ = &ast.RowExpr{Values: values} - } -| "EXISTS" SubSelect - { - sq := $2.(*ast.SubqueryExpr) - sq.Exists = true - $$ = &ast.ExistsSubqueryExpr{Sel: sq} - } -| "BINARY" SimpleExpr %prec neg - { - // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#operator_binary - x := types.NewFieldType(mysql.TypeString) - x.Charset = charset.CharsetBin - x.Collate = charset.CharsetBin - $$ = &ast.FuncCastExpr{ - Expr: $2, - Tp: x, - FunctionType: ast.CastBinaryOperator, - } - } -| builtinCast '(' Expression "AS" CastType ')' - { - /* See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast */ - tp := $5.(*types.FieldType) - defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.Tp) - if tp.Flen == types.UnspecifiedLength { - tp.Flen = defaultFlen - } - if tp.Decimal == types.UnspecifiedLength { - tp.Decimal = defaultDecimal - } - $$ = &ast.FuncCastExpr{ - Expr: $3, - Tp: tp, - FunctionType: ast.CastFunction, - } - } -| "CASE" ExpressionOpt WhenClauseList ElseOpt "END" - { - x := &ast.CaseExpr{WhenClauses: $3.([]*ast.WhenClause)} - if $2 != nil { - x.Value = $2 - } - if $4 != nil { - x.ElseClause = $4.(ast.ExprNode) - } - $$ = x - } -| "CONVERT" '(' Expression ',' CastType ')' - { - // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert - tp := $5.(*types.FieldType) - defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.Tp) - if tp.Flen == types.UnspecifiedLength { - tp.Flen = defaultFlen - } - if tp.Decimal == types.UnspecifiedLength { - tp.Decimal = defaultDecimal - } - $$ = &ast.FuncCastExpr{ - Expr: $3, - Tp: tp, - FunctionType: ast.CastConvertFunction, - } - } -| "CONVERT" '(' Expression "USING" StringName ')' - { - // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert - charset1 := ast.NewValueExpr($5) - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$3, charset1}, - } - } -| "DEFAULT" '(' SimpleIdent ')' - { - $$ = &ast.DefaultExpr{Name: $3.(*ast.ColumnNameExpr).Name} - } -| "VALUES" '(' SimpleIdent ')' %prec lowerThanInsertValues - { - $$ = &ast.ValuesExpr{Column: $3.(*ast.ColumnNameExpr)} - } -| SimpleIdent jss stringLit - { - expr := ast.NewValueExpr($3) - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}} - } -| SimpleIdent juss stringLit - { - expr := ast.NewValueExpr($3) - extract := &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}} - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONUnquote), Args: []ast.ExprNode{extract}} - } - -DistinctKwd: - "DISTINCT" -| "DISTINCTROW" - -DistinctOpt: - "ALL" - { - $$ = false - } -| DistinctKwd - { - $$ = true - } - -DefaultFalseDistinctOpt: - { - $$ = false - } -| DistinctOpt - -DefaultTrueDistinctOpt: - { - $$ = true - } -| DistinctOpt - -BuggyDefaultFalseDistinctOpt: - DefaultFalseDistinctOpt -| DistinctKwd "ALL" - { - $$ = true - } - - -FunctionNameConflict: - "ASCII" -| "CHARSET" -| "COALESCE" -| "COLLATION" -| "DATE" -| "DATABASE" -| "DAY" -| "HOUR" -| "IF" -| "INTERVAL" %prec lowerThanIntervalKeyword -| "FORMAT" -| "LEFT" -| "MICROSECOND" -| "MINUTE" -| "MONTH" -| builtinNow -| "QUARTER" -| "REPEAT" -| "REPLACE" -| "REVERSE" -| "RIGHT" -| "ROW_COUNT" -| "SECOND" -| "TIME" -| "TIMESTAMP" -| "TRUNCATE" -| "USER" -| "WEEK" -| "YEAR" - -OptionalBraces: - {} | '(' ')' {} - -FunctionNameOptionalBraces: - "CURRENT_USER" -| "CURRENT_DATE" -| "UTC_DATE" - -FunctionNameDatetimePrecision: - "CURRENT_TIME" -| "CURRENT_TIMESTAMP" -| "LOCALTIME" -| "LOCALTIMESTAMP" -| "UTC_TIME" -| "UTC_TIMESTAMP" - -FunctionCallKeyword: - FunctionNameConflict '(' ExpressionListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} - } -| builtinUser '(' ExpressionListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} - } -| FunctionNameOptionalBraces OptionalBraces - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)} - } -| builtinCurDate '(' ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)} - } -| FunctionNameDatetimePrecision FuncDatetimePrec - { - args := []ast.ExprNode{} - if $2 != nil { - args = append(args, $2.(ast.ExprNode)) - } - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: args} - } -| "CHAR" '(' ExpressionList ')' - { - nilVal := ast.NewValueExpr(nil) - args := $3.([]ast.ExprNode) - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr(ast.CharFunc), - Args: append(args, nilVal), - } - } -| "CHAR" '(' ExpressionList "USING" StringName ')' - { - charset1 := ast.NewValueExpr($5) - args := $3.([]ast.ExprNode) - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr(ast.CharFunc), - Args: append(args, charset1), - } - } -| "DATE" stringLit - { - expr := ast.NewValueExpr($2) - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.DateLiteral), Args: []ast.ExprNode{expr}} - } -| "TIME" stringLit - { - expr := ast.NewValueExpr($2) - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimeLiteral), Args: []ast.ExprNode{expr}} - } -| "TIMESTAMP" stringLit - { - expr := ast.NewValueExpr($2) - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimestampLiteral), Args: []ast.ExprNode{expr}} - } -| "INSERT" '(' ExpressionListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName:model.NewCIStr(ast.InsertFunc), Args: $3.([]ast.ExprNode)} - } -| "MOD" '(' BitExpr ',' BitExpr ')' - { - $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $3, R: $5} - } -| "PASSWORD" '(' ExpressionListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName:model.NewCIStr(ast.PasswordFunc), Args: $3.([]ast.ExprNode)} - } -| '{' ODBCDateTimeType stringLit '}' - { - // This is ODBC syntax for date and time literals. - // See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-literals.html - expr := ast.NewValueExpr($3) - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($2), Args: []ast.ExprNode{expr}} - } - -FunctionCallNonKeyword: - builtinCurTime '(' FuncDatetimePrecListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} - } -| builtinSysDate '(' FuncDatetimePrecListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} - } -| FunctionNameDateArithMultiForms '(' Expression ',' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{ - $3, - $5, - ast.NewValueExpr("DAY"), - }, - } - } -| FunctionNameDateArithMultiForms '(' Expression ',' "INTERVAL" Expression TimeUnit ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{ - $3, - $6, - ast.NewValueExpr($7), - }, - } - } -| FunctionNameDateArith '(' Expression ',' "INTERVAL" Expression TimeUnit ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{ - $3, - $6, - ast.NewValueExpr($7), - }, - } - } -| builtinExtract '(' TimeUnit "FROM" Expression ')' - { - timeUnit := ast.NewValueExpr($3) - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{timeUnit, $5}, - } - } -| "GET_FORMAT" '(' GetFormatSelector ',' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{ast.NewValueExpr($3), $5}, - } - } -| builtinPosition '(' BitExpr "IN" Expression ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: []ast.ExprNode{$3, $5}} - } -| builtinSubstring '(' Expression ',' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$3, $5}, - } - } -| builtinSubstring '(' Expression "FROM" Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$3, $5}, - } - } -| builtinSubstring '(' Expression ',' Expression ',' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$3, $5, $7}, - } - } -| builtinSubstring '(' Expression "FROM" Expression "FOR" Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$3, $5, $7}, - } - } -| "TIMESTAMPADD" '(' TimestampUnit ',' Expression ',' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{ast.NewValueExpr($3), $5, $7}, - } - } -| "TIMESTAMPDIFF" '(' TimestampUnit ',' Expression ',' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{ast.NewValueExpr($3), $5, $7}, - } - } -| builtinTrim '(' Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$3}, - } - } -| builtinTrim '(' Expression "FROM" Expression ')' - { - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$5, $3}, - } - } -| builtinTrim '(' TrimDirection "FROM" Expression ')' - { - nilVal := ast.NewValueExpr(nil) - direction := ast.NewValueExpr(int($3.(ast.TrimDirectionType))) - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$5, nilVal, direction}, - } - } -| builtinTrim '(' TrimDirection Expression "FROM" Expression ')' - { - direction := ast.NewValueExpr(int($3.(ast.TrimDirectionType))) - $$ = &ast.FuncCallExpr{ - FnName: model.NewCIStr($1), - Args: []ast.ExprNode{$6, $4, direction}, - } - } - -GetFormatSelector: - "DATE" - { - $$ = strings.ToUpper($1) - } -| "DATETIME" - { - $$ = strings.ToUpper($1) - } -| "TIME" - { - $$ = strings.ToUpper($1) - } -| "TIMESTAMP" - { - $$ = strings.ToUpper($1) - } - - -FunctionNameDateArith: - builtinDateAdd -| builtinDateSub - - -FunctionNameDateArithMultiForms: - builtinAddDate -| builtinSubDate - - -TrimDirection: - "BOTH" - { - $$ = ast.TrimBoth - } -| "LEADING" - { - $$ = ast.TrimLeading - } -| "TRAILING" - { - $$ = ast.TrimTrailing - } - -SumExpr: - "AVG" '(' BuggyDefaultFalseDistinctOpt Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} - } -| builtinBitAnd '(' Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} - } -| builtinBitAnd '(' "ALL" Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} - } -| builtinBitOr '(' Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} - } -| builtinBitOr '(' "ALL" Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} - } -| builtinBitXor '(' Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} - } -| builtinBitXor '(' "ALL" Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} - } -| builtinCount '(' DistinctKwd ExpressionList ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: $4.([]ast.ExprNode), Distinct: true} - } -| builtinCount '(' "ALL" Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} - } -| builtinCount '(' Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} - } -| builtinCount '(' '*' ')' - { - args := []ast.ExprNode{ast.NewValueExpr(1)} - $$ = &ast.AggregateFuncExpr{F: $1, Args: args} - } -| builtinGroupConcat '(' BuggyDefaultFalseDistinctOpt ExpressionList OrderByOptional OptGConcatSeparator ')' - { - args := $4.([]ast.ExprNode) - args = append(args, $6.(ast.ExprNode)) - $$ = &ast.AggregateFuncExpr{F: $1, Args: args, Distinct: $3.(bool)} - } -| builtinMax '(' BuggyDefaultFalseDistinctOpt Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} - } -| builtinMin '(' BuggyDefaultFalseDistinctOpt Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} - } -| builtinSum '(' BuggyDefaultFalseDistinctOpt Expression ')' - { - $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} - } - -OptGConcatSeparator: - { - $$ = ast.NewValueExpr(",") - } -| "SEPARATOR" stringLit - { - $$ = ast.NewValueExpr($2) - } - - -FunctionCallGeneric: - identifier '(' ExpressionListOpt ')' - { - $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} - } - -FuncDatetimePrec: - { - $$ = nil - } -| '(' ')' - { - $$ = nil - } -| '(' intLit ')' - { - expr := ast.NewValueExpr($2) - $$ = expr - } - -TimeUnit: - "MICROSECOND" - { - $$ = strings.ToUpper($1) - } -| "SECOND" - { - $$ = strings.ToUpper($1) - } -| "MINUTE" - { - $$ = strings.ToUpper($1) - } -| "HOUR" - { - $$ = strings.ToUpper($1) - } -| "DAY" - { - $$ = strings.ToUpper($1) - } -| "WEEK" - { - $$ = strings.ToUpper($1) - } -| "MONTH" - { - $$ = strings.ToUpper($1) - } -| "QUARTER" - { - $$ = strings.ToUpper($1) - } -| "YEAR" - { - $$ = strings.ToUpper($1) - } -| "SECOND_MICROSECOND" - { - $$ = strings.ToUpper($1) - } -| "MINUTE_MICROSECOND" - { - $$ = strings.ToUpper($1) - } -| "MINUTE_SECOND" - { - $$ = strings.ToUpper($1) - } -| "HOUR_MICROSECOND" - { - $$ = strings.ToUpper($1) - } -| "HOUR_SECOND" - { - $$ = strings.ToUpper($1) - } -| "HOUR_MINUTE" - { - $$ = strings.ToUpper($1) - } -| "DAY_MICROSECOND" - { - $$ = strings.ToUpper($1) - } -| "DAY_SECOND" - { - $$ = strings.ToUpper($1) - } -| "DAY_MINUTE" - { - $$ = strings.ToUpper($1) - } -| "DAY_HOUR" - { - $$ = strings.ToUpper($1) - } -| "YEAR_MONTH" - { - $$ = strings.ToUpper($1) - } - -TimestampUnit: - "MICROSECOND" - { - $$ = strings.ToUpper($1) - } -| "SECOND" - { - $$ = strings.ToUpper($1) - } -| "MINUTE" - { - $$ = strings.ToUpper($1) - } -| "HOUR" - { - $$ = strings.ToUpper($1) - } -| "DAY" - { - $$ = strings.ToUpper($1) - } -| "WEEK" - { - $$ = strings.ToUpper($1) - } -| "MONTH" - { - $$ = strings.ToUpper($1) - } -| "QUARTER" - { - $$ = strings.ToUpper($1) - } -| "YEAR" - { - $$ = strings.ToUpper($1) - } - -ExpressionOpt: - { - $$ = nil - } -| Expression - { - $$ = $1 - } - -WhenClauseList: - WhenClause - { - $$ = []*ast.WhenClause{$1.(*ast.WhenClause)} - } -| WhenClauseList WhenClause - { - $$ = append($1.([]*ast.WhenClause), $2.(*ast.WhenClause)) - } - -WhenClause: - "WHEN" Expression "THEN" Expression - { - $$ = &ast.WhenClause{ - Expr: $2, - Result: $4, - } - } - -ElseOpt: - /* empty */ - { - $$ = nil - } -| "ELSE" Expression - { - $$ = $2 - } - -CastType: - "BINARY" OptFieldLen - { - x := types.NewFieldType(mysql.TypeVarString) - x.Flen = $2.(int) // TODO: Flen should be the flen of expression - if x.Flen != types.UnspecifiedLength { - x.Tp = mysql.TypeString - } - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "CHAR" OptFieldLen OptBinary - { - x := types.NewFieldType(mysql.TypeVarString) - x.Flen = $2.(int) // TODO: Flen should be the flen of expression - x.Charset = $3.(*ast.OptBinary).Charset - if $3.(*ast.OptBinary).IsBinary{ - x.Flag |= mysql.BinaryFlag - } - if x.Charset == "" { - x.Charset = charset.CharsetUTF8MB4 - x.Collate = charset.CollationUTF8MB4 - } - $$ = x - } -| "DATE" - { - x := types.NewFieldType(mysql.TypeDate) - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "DATETIME" OptFieldLen - { - x := types.NewFieldType(mysql.TypeDatetime) - x.Flen, _ = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDatetime) - x.Decimal = $2.(int) - if x.Decimal > 0 { - x.Flen = x.Flen + 1 + x.Decimal - } - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "DECIMAL" FloatOpt - { - fopt := $2.(*ast.FloatOpt) - x := types.NewFieldType(mysql.TypeNewDecimal) - x.Flen = fopt.Flen - x.Decimal = fopt.Decimal - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "TIME" OptFieldLen - { - x := types.NewFieldType(mysql.TypeDuration) - x.Flen, _ = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDuration) - x.Decimal = $2.(int) - if x.Decimal > 0 { - x.Flen = x.Flen + 1 + x.Decimal - } - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "SIGNED" OptInteger - { - x := types.NewFieldType(mysql.TypeLonglong) - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "UNSIGNED" OptInteger - { - x := types.NewFieldType(mysql.TypeLonglong) - x.Flag |= mysql.UnsignedFlag | mysql.BinaryFlag - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - $$ = x - } -| "JSON" - { - x := types.NewFieldType(mysql.TypeJSON) - x.Flag |= mysql.BinaryFlag | (mysql.ParseToJSONFlag) - x.Charset = charset.CharsetUTF8MB4 - x.Collate = charset.CollationUTF8MB4 - $$ = x - } - -PriorityOpt: - { - $$ = mysql.NoPriority - } -| "LOW_PRIORITY" - { - $$ = mysql.LowPriority - } -| "HIGH_PRIORITY" - { - $$ = mysql.HighPriority - } -| "DELAYED" - { - $$ = mysql.DelayedPriority - } - -TableName: - Identifier - { - $$ = &ast.TableName{Name:model.NewCIStr($1)} - } -| Identifier '.' Identifier - { - $$ = &ast.TableName{Schema:model.NewCIStr($1), Name:model.NewCIStr($3)} - } - -TableNameList: - TableName - { - tbl := []*ast.TableName{$1.(*ast.TableName)} - $$ = tbl - } -| TableNameList ',' TableName - { - $$ = append($1.([]*ast.TableName), $3.(*ast.TableName)) - } - -QuickOptional: - %prec empty - { - $$ = false - } -| "QUICK" - { - $$ = true - } - -/***************************Prepared Statement Start****************************** - * See https://dev.mysql.com/doc/refman/5.7/en/prepare.html - * Example: - * PREPARE stmt_name FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse'; - * OR - * SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse'; - * PREPARE stmt_name FROM @s; - */ - -PreparedStmt: - "PREPARE" Identifier "FROM" PrepareSQL - { - var sqlText string - var sqlVar *ast.VariableExpr - switch $4.(type) { - case string: - sqlText = $4.(string) - case *ast.VariableExpr: - sqlVar = $4.(*ast.VariableExpr) - } - $$ = &ast.PrepareStmt{ - Name: $2, - SQLText: sqlText, - SQLVar: sqlVar, - } - } - -PrepareSQL: - stringLit - { - $$ = $1 - } -| UserVariable - { - $$ = $1.(interface{}) - } - - -/* - * See https://dev.mysql.com/doc/refman/5.7/en/execute.html - * Example: - * EXECUTE stmt1 USING @a, @b; - * OR - * EXECUTE stmt1; - */ -ExecuteStmt: - "EXECUTE" Identifier - { - $$ = &ast.ExecuteStmt{Name: $2} - } -| "EXECUTE" Identifier "USING" UserVariableList - { - $$ = &ast.ExecuteStmt{ - Name: $2, - UsingVars: $4.([]ast.ExprNode), - } - } - -UserVariableList: - UserVariable - { - $$ = []ast.ExprNode{$1} - } -| UserVariableList ',' UserVariable - { - $$ = append($1.([]ast.ExprNode), $3) - } - -/* - * See https://dev.mysql.com/doc/refman/5.0/en/deallocate-prepare.html - */ - -DeallocateStmt: - DeallocateSym "PREPARE" Identifier - { - $$ = &ast.DeallocateStmt{Name: $3} - } - -DeallocateSym: -"DEALLOCATE" | "DROP" - -/****************************Prepared Statement End*******************************/ - - -RollbackStmt: - "ROLLBACK" - { - $$ = &ast.RollbackStmt{} - } - -SelectStmtBasic: - "SELECT" SelectStmtOpts SelectStmtFieldList - { - st := &ast.SelectStmt { - SelectStmtOpts: $2.(*ast.SelectStmtOpts), - Distinct: $2.(*ast.SelectStmtOpts).Distinct, - Fields: $3.(*ast.FieldList), - } - $$ = st - } - -SelectStmtFromDual: - SelectStmtBasic FromDual WhereClauseOptional OrderByOptional - { - st := $1.(*ast.SelectStmt) - lastField := st.Fields.Fields[len(st.Fields.Fields)-1] - if lastField.Expr != nil && lastField.AsName.O == "" { - lastEnd := yyS[yypt-2].offset-1 - lastField.SetText(parser.src[lastField.Offset:lastEnd]) - } - if $3 != nil { - st.Where = $3.(ast.ExprNode) - } - - if $4 != nil { - st.OrderBy = $4.(*ast.OrderByClause) - } - } - - -SelectStmtFromTable: - SelectStmtBasic "FROM" - TableRefsClause WhereClauseOptional SelectStmtGroup HavingClause - { - st := $1.(*ast.SelectStmt) - st.From = $3.(*ast.TableRefsClause) - if st.SelectStmtOpts.TableHints != nil { - st.TableHints = st.SelectStmtOpts.TableHints - } - lastField := st.Fields.Fields[len(st.Fields.Fields)-1] - if lastField.Expr != nil && lastField.AsName.O == "" { - lastEnd := parser.endOffset(&yyS[yypt-4]) - lastField.SetText(parser.src[lastField.Offset:lastEnd]) - } - if $4 != nil { - st.Where = $4.(ast.ExprNode) - } - if $5 != nil { - st.GroupBy = $5.(*ast.GroupByClause) - } - if $6 != nil { - st.Having = $6.(*ast.HavingClause) - } - $$ = st - } - -SelectStmt: - SelectStmtBasic OrderByOptional SelectStmtLimit SelectLockOpt - { - st := $1.(*ast.SelectStmt) - st.LockTp = $4.(ast.SelectLockType) - lastField := st.Fields.Fields[len(st.Fields.Fields)-1] - if lastField.Expr != nil && lastField.AsName.O == "" { - src := parser.src - var lastEnd int - if $2 != nil { - lastEnd = yyS[yypt-2].offset-1 - } else if $3 != nil { - lastEnd = yyS[yypt-1].offset-1 - } else if $4 != ast.SelectLockNone { - lastEnd = yyS[yypt].offset-1 - } else { - lastEnd = len(src) - if src[lastEnd-1] == ';' { - lastEnd-- - } - } - lastField.SetText(src[lastField.Offset:lastEnd]) - } - if $2 != nil { - st.OrderBy = $2.(*ast.OrderByClause) - } - if $3 != nil { - st.Limit = $3.(*ast.Limit) - } - $$ = st - } -| SelectStmtFromDual SelectStmtLimit SelectLockOpt - { - st := $1.(*ast.SelectStmt) - st.LockTp = $3.(ast.SelectLockType) - if $2 != nil { - st.Limit = $2.(*ast.Limit) - } - $$ = st - } -| SelectStmtFromTable OrderByOptional SelectStmtLimit SelectLockOpt - { - st := $1.(*ast.SelectStmt) - st.LockTp = $4.(ast.SelectLockType) - if $2 != nil { - st.OrderBy = $2.(*ast.OrderByClause) - } - if $3 != nil { - st.Limit = $3.(*ast.Limit) - } - $$ = st - } - -FromDual: - "FROM" "DUAL" - - -TableRefsClause: - TableRefs - { - $$ = &ast.TableRefsClause{TableRefs: $1.(*ast.Join)} - } - -TableRefs: - EscapedTableRef - { - if j, ok := $1.(*ast.Join); ok { - // if $1 is Join, use it directly - $$ = j - } else { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: nil} - } - } -| TableRefs ',' EscapedTableRef - { - /* from a, b is default cross join */ - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin} - } - -EscapedTableRef: - TableRef %prec lowerThanSetKeyword - { - $$ = $1 - } -| '{' Identifier TableRef '}' - { - /* - * ODBC escape syntax for outer join is { OJ join_table } - * Use an Identifier for OJ - */ - $$ = $3 - } - -TableRef: - TableFactor - { - $$ = $1 - } -| JoinTable - { - $$ = $1 - } - -TableFactor: - TableName TableAsNameOpt IndexHintListOpt - { - tn := $1.(*ast.TableName) - tn.IndexHints = $3.([]*ast.IndexHint) - $$ = &ast.TableSource{Source: tn, AsName: $2.(model.CIStr)} - } -| '(' SelectStmt ')' TableAsName - { - st := $2.(*ast.SelectStmt) - endOffset := parser.endOffset(&yyS[yypt-1]) - parser.setLastSelectFieldText(st, endOffset) - $$ = &ast.TableSource{Source: $2.(*ast.SelectStmt), AsName: $4.(model.CIStr)} - } -| '(' UnionStmt ')' TableAsName - { - $$ = &ast.TableSource{Source: $2.(*ast.UnionStmt), AsName: $4.(model.CIStr)} - } -| '(' TableRefs ')' - { - $$ = $2 - } - -TableAsNameOpt: - { - $$ = model.CIStr{} - } -| TableAsName - { - $$ = $1 - } - -TableAsName: - Identifier - { - $$ = model.NewCIStr($1) - } -| "AS" Identifier - { - $$ = model.NewCIStr($2) - } - -IndexHintType: - "USE" KeyOrIndex - { - $$ = ast.HintUse - } -| "IGNORE" KeyOrIndex - { - $$ = ast.HintIgnore - } -| "FORCE" KeyOrIndex - { - $$ = ast.HintForce - } - -IndexHintScope: - { - $$ = ast.HintForScan - } -| "FOR" "JOIN" - { - $$ = ast.HintForJoin - } -| "FOR" "ORDER" "BY" - { - $$ = ast.HintForOrderBy - } -| "FOR" "GROUP" "BY" - { - $$ = ast.HintForGroupBy - } - - -IndexHint: - IndexHintType IndexHintScope '(' IndexNameList ')' - { - $$ = &ast.IndexHint{ - IndexNames: $4.([]model.CIStr), - HintType: $1.(ast.IndexHintType), - HintScope: $2.(ast.IndexHintScope), - } - } - -IndexNameList: - { - var nameList []model.CIStr - $$ = nameList - } -| Identifier - { - $$ = []model.CIStr{model.NewCIStr($1)} - } -| IndexNameList ',' Identifier - { - $$ = append($1.([]model.CIStr), model.NewCIStr($3)) - } - - -IndexHintList: - IndexHint - { - $$ = []*ast.IndexHint{$1.(*ast.IndexHint)} - } -| IndexHintList IndexHint - { - $$ = append($1.([]*ast.IndexHint), $2.(*ast.IndexHint)) - } - -IndexHintListOpt: - { - var hintList []*ast.IndexHint - $$ = hintList - } -| IndexHintList - { - $$ = $1 - } - -JoinTable: - /* Use %prec to evaluate production TableRef before cross join */ - TableRef CrossOpt TableRef %prec tableRefPriority - { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin} - } -| TableRef CrossOpt TableRef "ON" Expression - { - on := &ast.OnCondition{Expr: $5} - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, On: on} - } -| TableRef CrossOpt TableRef "USING" '(' ColumnNameList ')' - { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, Using: $6.([]*ast.ColumnName)} - } -| TableRef JoinType OuterOpt "JOIN" TableRef "ON" Expression - { - on := &ast.OnCondition{Expr: $7} - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), On: on} - } -| TableRef JoinType OuterOpt "JOIN" TableRef "USING" '(' ColumnNameList ')' - { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), Using: $8.([]*ast.ColumnName)} - } -| TableRef "NATURAL" "JOIN" TableRef - { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $4.(ast.ResultSetNode), NaturalJoin: true} - } -| TableRef "NATURAL" JoinType OuterOpt "JOIN" TableRef - { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $6.(ast.ResultSetNode), Tp: $3.(ast.JoinType), NaturalJoin: true} - } -| TableRef "STRAIGHT_JOIN" TableRef - { - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true} - } -| TableRef "STRAIGHT_JOIN" TableRef "ON" Expression - { - on := &ast.OnCondition{Expr: $5} - $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true, On: on} - } - -JoinType: - "LEFT" - { - $$ = ast.LeftJoin - } -| "RIGHT" - { - $$ = ast.RightJoin - } - -OuterOpt: - {} -| "OUTER" - -CrossOpt: - "JOIN" -| "CROSS" "JOIN" -| "INNER" "JOIN" - - -LimitClause: - { - $$ = nil - } -| "LIMIT" LimitOption - { - $$ = &ast.Limit{Count: $2.(ast.ValueExpr)} - } - -LimitOption: - LengthNum - { - $$ = ast.NewValueExpr($1) - } -| paramMarker - { - $$ = ast.NewParamMarkerExpr(yyS[yypt].offset) - } - -SelectStmtLimit: - { - $$ = nil - } -| "LIMIT" LimitOption - { - $$ = &ast.Limit{Count: $2.(ast.ExprNode)} - } -| "LIMIT" LimitOption ',' LimitOption - { - $$ = &ast.Limit{Offset: $2.(ast.ExprNode), Count: $4.(ast.ExprNode)} - } -| "LIMIT" LimitOption "OFFSET" LimitOption - { - $$ = &ast.Limit{Offset: $4.(ast.ExprNode), Count: $2.(ast.ExprNode)} - } - - -SelectStmtOpts: - TableOptimizerHints DefaultFalseDistinctOpt PriorityOpt SelectStmtSQLCache SelectStmtCalcFoundRows SelectStmtStraightJoin - { - opt := &ast.SelectStmtOpts{} - if $1 != nil { - opt.TableHints = $1.([]*ast.TableOptimizerHint) - } - if $2 != nil { - opt.Distinct = $2.(bool) - } - if $3 != nil { - opt.Priority = $3.(mysql.PriorityEnum) - } - if $4 != nil { - opt.SQLCache = $4.(bool) - } - if $5 != nil { - opt.CalcFoundRows = $5.(bool) - } - if $6 != nil { - opt.StraightJoin = $6.(bool) - } - - $$ = opt - } - -TableOptimizerHints: - /* empty */ - { - $$ = nil - } -| hintBegin TableOptimizerHintList hintEnd - { - $$ = $2 - } - -HintTableList: - Identifier - { - $$ = []model.CIStr{model.NewCIStr($1)} - } -| HintTableList ',' Identifier - { - $$ = append($1.([]model.CIStr), model.NewCIStr($3)) - } - -TableOptimizerHintList: - TableOptimizerHintOpt - { - $$ = []*ast.TableOptimizerHint{$1.(*ast.TableOptimizerHint)} - } -| TableOptimizerHintList TableOptimizerHintOpt - { - $$ = append($1.([]*ast.TableOptimizerHint), $2.(*ast.TableOptimizerHint)) - } - -TableOptimizerHintOpt: - tidbSMJ '(' HintTableList ')' - { - $$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), Tables: $3.([]model.CIStr)} - } -| tidbINLJ '(' HintTableList ')' - { - $$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), Tables: $3.([]model.CIStr)} - } -| tidbHJ '(' HintTableList ')' - { - $$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), Tables: $3.([]model.CIStr)} - } -| maxExecutionTime '(' NUM ')' - { - $$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), MaxExecutionTime: getUint64FromNUM($3)} - } - -SelectStmtCalcFoundRows: - { - $$ = false - } -| "SQL_CALC_FOUND_ROWS" - { - $$ = true - } -SelectStmtSQLCache: - %prec empty - { - $$ = true - } -| "SQL_CACHE" - { - $$ = true - } -| "SQL_NO_CACHE" - { - $$ = false - } -SelectStmtStraightJoin: - %prec empty - { - $$ = false - } -| "STRAIGHT_JOIN" - { - $$ = true - } - -SelectStmtFieldList: - FieldList - { - $$ = &ast.FieldList{Fields: $1.([]*ast.SelectField)} - } - -SelectStmtGroup: - /* EMPTY */ - { - $$ = nil - } -| GroupByClause - -// See https://dev.mysql.com/doc/refman/5.7/en/subqueries.html -SubSelect: - '(' SelectStmt ')' - { - s := $2.(*ast.SelectStmt) - endOffset := parser.endOffset(&yyS[yypt]) - parser.setLastSelectFieldText(s, endOffset) - src := parser.src - // See the implementation of yyParse function - s.SetText(src[yyS[yypt-1].offset:yyS[yypt].offset]) - $$ = &ast.SubqueryExpr{Query: s} - } -| '(' UnionStmt ')' - { - s := $2.(*ast.UnionStmt) - src := parser.src - // See the implementation of yyParse function - s.SetText(src[yyS[yypt-1].offset:yyS[yypt].offset]) - $$ = &ast.SubqueryExpr{Query: s} - } - -// See https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html -SelectLockOpt: - /* empty */ - { - $$ = ast.SelectLockNone - } -| "FOR" "UPDATE" - { - $$ = ast.SelectLockForUpdate - } -| "LOCK" "IN" "SHARE" "MODE" - { - $$ = ast.SelectLockInShareMode - } - -// See https://dev.mysql.com/doc/refman/5.7/en/union.html -UnionStmt: - UnionClauseList "UNION" UnionOpt SelectStmtBasic OrderByOptional SelectStmtLimit SelectLockOpt - { - st := $4.(*ast.SelectStmt) - union := $1.(*ast.UnionStmt) - st.IsAfterUnionDistinct = $3.(bool) - lastSelect := union.SelectList.Selects[len(union.SelectList.Selects)-1] - endOffset := parser.endOffset(&yyS[yypt-5]) - parser.setLastSelectFieldText(lastSelect, endOffset) - union.SelectList.Selects = append(union.SelectList.Selects, st) - if $5 != nil { - union.OrderBy = $5.(*ast.OrderByClause) - } - if $6 != nil { - union.Limit = $6.(*ast.Limit) - } - if $5 == nil && $6 == nil { - st.LockTp = $7.(ast.SelectLockType) - } - $$ = union - } -| UnionClauseList "UNION" UnionOpt SelectStmtFromDual SelectStmtLimit SelectLockOpt - { - st := $4.(*ast.SelectStmt) - union := $1.(*ast.UnionStmt) - st.IsAfterUnionDistinct = $3.(bool) - lastSelect := union.SelectList.Selects[len(union.SelectList.Selects)-1] - endOffset := parser.endOffset(&yyS[yypt-4]) - parser.setLastSelectFieldText(lastSelect, endOffset) - union.SelectList.Selects = append(union.SelectList.Selects, st) - if $5 != nil { - union.Limit = $5.(*ast.Limit) - } else { - st.LockTp = $6.(ast.SelectLockType) - } - $$ = union - } -| UnionClauseList "UNION" UnionOpt SelectStmtFromTable OrderByOptional - SelectStmtLimit SelectLockOpt - { - st := $4.(*ast.SelectStmt) - union := $1.(*ast.UnionStmt) - st.IsAfterUnionDistinct = $3.(bool) - lastSelect := union.SelectList.Selects[len(union.SelectList.Selects)-1] - endOffset := parser.endOffset(&yyS[yypt-5]) - parser.setLastSelectFieldText(lastSelect, endOffset) - union.SelectList.Selects = append(union.SelectList.Selects, st) - if $5 != nil { - union.OrderBy = $5.(*ast.OrderByClause) - } - if $6 != nil { - union.Limit = $6.(*ast.Limit) - } - if $5 == nil && $6 == nil { - st.LockTp = $7.(ast.SelectLockType) - } - $$ = union - } -| UnionClauseList "UNION" UnionOpt '(' SelectStmt ')' OrderByOptional SelectStmtLimit - { - union := $1.(*ast.UnionStmt) - lastSelect := union.SelectList.Selects[len(union.SelectList.Selects)-1] - endOffset := parser.endOffset(&yyS[yypt-6]) - parser.setLastSelectFieldText(lastSelect, endOffset) - st := $5.(*ast.SelectStmt) - st.IsInBraces = true - st.IsAfterUnionDistinct = $3.(bool) - endOffset = parser.endOffset(&yyS[yypt-2]) - parser.setLastSelectFieldText(st, endOffset) - union.SelectList.Selects = append(union.SelectList.Selects, st) - if $7 != nil { - union.OrderBy = $7.(*ast.OrderByClause) - } - if $8 != nil { - union.Limit = $8.(*ast.Limit) - } - $$ = union - } - -UnionClauseList: - UnionSelect - { - selectList := &ast.UnionSelectList{Selects: []*ast.SelectStmt{$1.(*ast.SelectStmt)}} - $$ = &ast.UnionStmt{ - SelectList: selectList, - } - } -| UnionClauseList "UNION" UnionOpt UnionSelect - { - union := $1.(*ast.UnionStmt) - st := $4.(*ast.SelectStmt) - st.IsAfterUnionDistinct = $3.(bool) - lastSelect := union.SelectList.Selects[len(union.SelectList.Selects)-1] - endOffset := parser.endOffset(&yyS[yypt-2]) - parser.setLastSelectFieldText(lastSelect, endOffset) - union.SelectList.Selects = append(union.SelectList.Selects, st) - $$ = union - } - -UnionSelect: - SelectStmt - { - $$ = $1.(interface{}) - } -| '(' SelectStmt ')' - { - st := $2.(*ast.SelectStmt) - st.IsInBraces = true - endOffset := parser.endOffset(&yyS[yypt]) - parser.setLastSelectFieldText(st, endOffset) - $$ = $2 - } - -UnionOpt: -DefaultTrueDistinctOpt - - -/********************Set Statement*******************************/ -SetStmt: - "SET" VariableAssignmentList - { - $$ = &ast.SetStmt{Variables: $2.([]*ast.VariableAssignment)} - } -| "SET" "PASSWORD" EQOrAssignmentEQ PasswordOpt - { - $$ = &ast.SetPwdStmt{Password: $4.(string)} - } -| "SET" "PASSWORD" "FOR" Username EQOrAssignmentEQ PasswordOpt - { - $$ = &ast.SetPwdStmt{User: $4.(*auth.UserIdentity), Password: $6.(string)} - } -| "SET" "GLOBAL" "TRANSACTION" TransactionChars - { - vars := $4.([]*ast.VariableAssignment) - for _, v := range vars { - v.IsGlobal = true - } - $$ = &ast.SetStmt{Variables: vars} - } -| "SET" "SESSION" "TRANSACTION" TransactionChars - { - $$ = &ast.SetStmt{Variables: $4.([]*ast.VariableAssignment)} - } -| "SET" "TRANSACTION" TransactionChars - { - assigns := $3.([]*ast.VariableAssignment) - for i:=0; i 24 { - x.Tp = mysql.TypeDouble - } - } - x.Decimal = fopt.Decimal - for _, o := range $3.([]*ast.TypeOpt) { - if o.IsUnsigned { - x.Flag |= mysql.UnsignedFlag - } - if o.IsZerofill { - x.Flag |= mysql.ZerofillFlag - } - } - $$ = x - } -| BitValueType OptFieldLen - { - x := types.NewFieldType($1.(byte)) - x.Flen = $2.(int) - if x.Flen == types.UnspecifiedLength || x.Flen == 0 { - x.Flen = 1 - } else if x.Flen > 64 { - yylex.Errorf("invalid field length %d for bit type, must in [1, 64]", x.Flen) - } - $$ = x - } - -IntegerType: - "TINYINT" - { - $$ = mysql.TypeTiny - } -| "SMALLINT" - { - $$ = mysql.TypeShort - } -| "MEDIUMINT" - { - $$ = mysql.TypeInt24 - } -| "INT" - { - $$ = mysql.TypeLong - } -| "INT1" - { - $$ = mysql.TypeTiny - } -| "INT2" - { - $$ = mysql.TypeShort - } -| "INT3" - { - $$ = mysql.TypeInt24 - } -| "INT4" - { - $$ = mysql.TypeLong - } -| "INT8" - { - $$ = mysql.TypeLonglong - } -| "INTEGER" - { - $$ = mysql.TypeLong - } -| "BIGINT" - { - $$ = mysql.TypeLonglong - } - - -BooleanType: - "BOOL" - { - $$ = mysql.TypeTiny - } -| "BOOLEAN" - { - $$ = mysql.TypeTiny - } - -OptInteger: - {} -| "INTEGER" -| "INT" - -FixedPointType: - "DECIMAL" - { - $$ = mysql.TypeNewDecimal - } -| "NUMERIC" - { - $$ = mysql.TypeNewDecimal - } - -FloatingPointType: - "FLOAT" - { - $$ = mysql.TypeFloat - } -| "REAL" - { - if parser.lexer.GetSQLMode().HasRealAsFloatMode() { - $$ = mysql.TypeFloat - } else { - $$ = mysql.TypeDouble - } - } -| "DOUBLE" - { - $$ = mysql.TypeDouble - } -| "DOUBLE" "PRECISION" - { - $$ = mysql.TypeDouble - } - -BitValueType: - "BIT" - { - $$ = mysql.TypeBit - } - -StringType: - NationalOpt "CHAR" FieldLen OptBinary OptCollate - { - x := types.NewFieldType(mysql.TypeString) - x.Flen = $3.(int) - x.Charset = $4.(*ast.OptBinary).Charset - x.Collate = $5.(string) - if $4.(*ast.OptBinary).IsBinary { - x.Flag |= mysql.BinaryFlag - } - $$ = x - } -| NationalOpt "CHAR" OptBinary OptCollate - { - x := types.NewFieldType(mysql.TypeString) - x.Charset = $3.(*ast.OptBinary).Charset - x.Collate = $4.(string) - if $3.(*ast.OptBinary).IsBinary { - x.Flag |= mysql.BinaryFlag - } - $$ = x - } -| "NATIONAL" "CHARACTER" FieldLen OptBinary OptCollate - { - x := types.NewFieldType(mysql.TypeString) - x.Flen = $3.(int) - x.Charset = $4.(*ast.OptBinary).Charset - x.Collate = $5.(string) - if $4.(*ast.OptBinary).IsBinary { - x.Flag |= mysql.BinaryFlag - } - $$ = x - } -| Varchar FieldLen OptBinary OptCollate - { - x := types.NewFieldType(mysql.TypeVarchar) - x.Flen = $2.(int) - x.Charset = $3.(*ast.OptBinary).Charset - x.Collate = $4.(string) - if $3.(*ast.OptBinary).IsBinary { - x.Flag |= mysql.BinaryFlag - } - $$ = x - } -| "BINARY" OptFieldLen - { - x := types.NewFieldType(mysql.TypeString) - x.Flen = $2.(int) - x.Charset = charset.CharsetBin - x.Collate = charset.CharsetBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| "VARBINARY" FieldLen - { - x := types.NewFieldType(mysql.TypeVarchar) - x.Flen = $2.(int) - x.Charset = charset.CharsetBin - x.Collate = charset.CharsetBin - x.Flag |= mysql.BinaryFlag - $$ = x - } -| BlobType - { - x := $1.(*types.FieldType) - x.Charset = charset.CharsetBin - x.Collate = charset.CharsetBin - x.Flag |= mysql.BinaryFlag - $$ = $1.(*types.FieldType) - } -| TextType OptBinary OptCollate - { - x := $1.(*types.FieldType) - x.Charset = $2.(*ast.OptBinary).Charset - x.Collate = $3.(string) - if $2.(*ast.OptBinary).IsBinary { - x.Flag |= mysql.BinaryFlag - } - $$ = x - } -| "ENUM" '(' StringList ')' OptCharset OptCollate - { - x := types.NewFieldType(mysql.TypeEnum) - x.Elems = $3.([]string) - x.Charset = $5.(string) - x.Collate = $6.(string) - $$ = x - } -| "SET" '(' StringList ')' OptCharset OptCollate - { - x := types.NewFieldType(mysql.TypeSet) - x.Elems = $3.([]string) - x.Charset = $5.(string) - x.Collate = $6.(string) - $$ = x - } -| "JSON" - { - x := types.NewFieldType(mysql.TypeJSON) - x.Decimal = 0 - x.Charset = charset.CharsetBin - x.Collate = charset.CollationBin - $$ = x - } - -NationalOpt: - {} -| "NATIONAL" - -Varchar: -"NATIONAL" "VARCHAR" -| "VARCHAR" -| "NVARCHAR" - - -BlobType: - "TINYBLOB" - { - x := types.NewFieldType(mysql.TypeTinyBlob) - $$ = x - } -| "BLOB" OptFieldLen - { - x := types.NewFieldType(mysql.TypeBlob) - x.Flen = $2.(int) - $$ = x - } -| "MEDIUMBLOB" - { - x := types.NewFieldType(mysql.TypeMediumBlob) - $$ = x - } -| "LONGBLOB" - { - x := types.NewFieldType(mysql.TypeLongBlob) - $$ = x - } - -TextType: - "TINYTEXT" - { - x := types.NewFieldType(mysql.TypeTinyBlob) - $$ = x - - } -| "TEXT" OptFieldLen - { - x := types.NewFieldType(mysql.TypeBlob) - x.Flen = $2.(int) - $$ = x - } -| "MEDIUMTEXT" - { - x := types.NewFieldType(mysql.TypeMediumBlob) - $$ = x - } -| "LONGTEXT" - { - x := types.NewFieldType(mysql.TypeLongBlob) - $$ = x - } -| "LONG" "VARCHAR" - { - x := types.NewFieldType(mysql.TypeMediumBlob) - $$ = x - } - - -DateAndTimeType: - "DATE" - { - x := types.NewFieldType(mysql.TypeDate) - $$ = x - } -| "DATETIME" OptFieldLen - { - x := types.NewFieldType(mysql.TypeDatetime) - x.Flen = mysql.MaxDatetimeWidthNoFsp - x.Decimal = $2.(int) - if x.Decimal > 0 { - x.Flen = x.Flen + 1 + x.Decimal - } - $$ = x - } -| "TIMESTAMP" OptFieldLen - { - x := types.NewFieldType(mysql.TypeTimestamp) - x.Flen = mysql.MaxDatetimeWidthNoFsp - x.Decimal = $2.(int) - if x.Decimal > 0 { - x.Flen = x.Flen + 1 + x.Decimal - } - $$ = x - } -| "TIME" OptFieldLen - { - x := types.NewFieldType(mysql.TypeDuration) - x.Flen = mysql.MaxDurationWidthNoFsp - x.Decimal = $2.(int) - if x.Decimal > 0 { - x.Flen = x.Flen + 1 + x.Decimal - } - $$ = x - } -| "YEAR" OptFieldLen FieldOpts - { - x := types.NewFieldType(mysql.TypeYear) - x.Flen = $2.(int) - if x.Flen != types.UnspecifiedLength && x.Flen != 4 { - yylex.Errorf("Supports only YEAR or YEAR(4) column.") - return -1 - } - $$ = x - } - -FieldLen: - '(' LengthNum ')' - { - $$ = int($2.(uint64)) - } - -OptFieldLen: - { - $$ = types.UnspecifiedLength - } -| FieldLen - { - $$ = $1.(int) - } - -FieldOpt: - "UNSIGNED" - { - $$ = &ast.TypeOpt{IsUnsigned: true} - } -| "SIGNED" - { - $$ = &ast.TypeOpt{IsUnsigned: false} - } -| "ZEROFILL" - { - $$ = &ast.TypeOpt{IsZerofill: true, IsUnsigned: true} - } - -FieldOpts: - { - $$ = []*ast.TypeOpt{} - } -| FieldOpts FieldOpt - { - $$ = append($1.([]*ast.TypeOpt), $2.(*ast.TypeOpt)) - } - -FloatOpt: - { - $$ = &ast.FloatOpt{Flen: types.UnspecifiedLength, Decimal: types.UnspecifiedLength} - } -| FieldLen - { - $$ = &ast.FloatOpt{Flen: $1.(int), Decimal: types.UnspecifiedLength} - } -| Precision - { - $$ = $1.(*ast.FloatOpt) - } - -Precision: - '(' LengthNum ',' LengthNum ')' - { - $$ = &ast.FloatOpt{Flen: int($2.(uint64)), Decimal: int($4.(uint64))} - } - -OptBinMod: - { - $$ = false - } -| "BINARY" - { - $$ = true - } - -OptBinary: - { - $$ = &ast.OptBinary{ - IsBinary: false, - Charset: "", - } - } -| "BINARY" OptCharset - { - $$ = &ast.OptBinary{ - IsBinary: true, - Charset: $2.(string), - } - } -| CharsetKw CharsetName OptBinMod - { - $$ = &ast.OptBinary{ - IsBinary: $3.(bool), - Charset: $2.(string), - } - } - -OptCharset: - { - $$ = "" - } -| CharsetKw CharsetName - { - $$ = $2.(string) - } - -CharsetKw: - "CHARACTER" "SET" -| "CHARSET" - -OptCollate: - { - $$ = "" - } -| "COLLATE" StringName - { - $$ = $2.(string) - } - -StringList: - stringLit - { - $$ = []string{$1} - } -| StringList ',' stringLit - { - $$ = append($1.([]string), $3) - } - -StringName: - stringLit - { - $$ = $1 - } -| Identifier - { - $$ = $1 - } - -/*********************************************************************************** - * Update Statement - * See https://dev.mysql.com/doc/refman/5.7/en/update.html - ***********************************************************************************/ -UpdateStmt: - "UPDATE" TableOptimizerHints PriorityOpt IgnoreOptional TableRef "SET" AssignmentList WhereClauseOptional OrderByOptional LimitClause - { - var refs *ast.Join - if x, ok := $5.(*ast.Join); ok { - refs = x - } else { - refs = &ast.Join{Left: $5.(ast.ResultSetNode)} - } - st := &ast.UpdateStmt{ - Priority: $3.(mysql.PriorityEnum), - TableRefs: &ast.TableRefsClause{TableRefs: refs}, - List: $7.([]*ast.Assignment), - IgnoreErr: $4.(bool), - } - if $2 != nil { - st.TableHints = $2.([]*ast.TableOptimizerHint) - } - if $8 != nil { - st.Where = $8.(ast.ExprNode) - } - if $9 != nil { - st.Order = $9.(*ast.OrderByClause) - } - if $10 != nil { - st.Limit = $10.(*ast.Limit) - } - $$ = st - } -| "UPDATE" TableOptimizerHints PriorityOpt IgnoreOptional TableRefs "SET" AssignmentList WhereClauseOptional - { - st := &ast.UpdateStmt{ - Priority: $3.(mysql.PriorityEnum), - TableRefs: &ast.TableRefsClause{TableRefs: $5.(*ast.Join)}, - List: $7.([]*ast.Assignment), - IgnoreErr: $4.(bool), - } - if $2 != nil { - st.TableHints = $2.([]*ast.TableOptimizerHint) - } - if $8 != nil { - st.Where = $8.(ast.ExprNode) - } - $$ = st - } - -UseStmt: - "USE" DBName - { - $$ = &ast.UseStmt{DBName: $2.(string)} - } - -WhereClause: - "WHERE" Expression - { - $$ = $2 - } - -WhereClauseOptional: - { - $$ = nil - } -| WhereClause - { - $$ = $1 - } - -CommaOpt: - {} -| ',' - {} - -/************************************************************************************ - * Account Management Statements - * https://dev.mysql.com/doc/refman/5.7/en/account-management-sql.html - ************************************************************************************/ -CreateUserStmt: - "CREATE" "USER" IfNotExists UserSpecList - { - // See https://dev.mysql.com/doc/refman/5.7/en/create-user.html - $$ = &ast.CreateUserStmt{ - IfNotExists: $3.(bool), - Specs: $4.([]*ast.UserSpec), - } - } - -/* See http://dev.mysql.com/doc/refman/5.7/en/alter-user.html */ -AlterUserStmt: - "ALTER" "USER" IfExists UserSpecList - { - $$ = &ast.AlterUserStmt{ - IfExists: $3.(bool), - Specs: $4.([]*ast.UserSpec), - } - } -| "ALTER" "USER" IfExists "USER" '(' ')' "IDENTIFIED" "BY" AuthString - { - auth := &ast.AuthOption { - AuthString: $9.(string), - ByAuthString: true, - } - $$ = &ast.AlterUserStmt{ - IfExists: $3.(bool), - CurrentAuth: auth, - } - } - -UserSpec: - Username AuthOption - { - userSpec := &ast.UserSpec{ - User: $1.(*auth.UserIdentity), - } - if $2 != nil { - userSpec.AuthOpt = $2.(*ast.AuthOption) - } - $$ = userSpec - } - -UserSpecList: - UserSpec - { - $$ = []*ast.UserSpec{$1.(*ast.UserSpec)} - } -| UserSpecList ',' UserSpec - { - $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec)) - } - -AuthOption: - { - $$ = nil - } -| "IDENTIFIED" "BY" AuthString - { - $$ = &ast.AuthOption { - AuthString: $3.(string), - ByAuthString: true, - } - } -| "IDENTIFIED" "WITH" StringName - { - $$ = nil - } -| "IDENTIFIED" "WITH" StringName "BY" AuthString - { - $$ = &ast.AuthOption { - AuthString: $5.(string), - ByAuthString: true, - } - } -| "IDENTIFIED" "WITH" StringName "AS" HashString - { - $$ = &ast.AuthOption{ - HashString: $5.(string), - } - } -| "IDENTIFIED" "BY" "PASSWORD" HashString - { - $$ = &ast.AuthOption{ - HashString: $4.(string), - } - } - -HashString: - stringLit - { - $$ = $1 - } - -/************************************************************************************* - * Grant statement - * See https://dev.mysql.com/doc/refman/5.7/en/grant.html - *************************************************************************************/ -GrantStmt: - "GRANT" PrivElemList "ON" ObjectType PrivLevel "TO" UserSpecList WithGrantOptionOpt - { - $$ = &ast.GrantStmt{ - Privs: $2.([]*ast.PrivElem), - ObjectType: $4.(ast.ObjectTypeType), - Level: $5.(*ast.GrantLevel), - Users: $7.([]*ast.UserSpec), - WithGrant: $8.(bool), - } - } - -WithGrantOptionOpt: - { - $$ = false - } -| "WITH" "GRANT" "OPTION" - { - $$ = true - } -| "WITH" "MAX_QUERIES_PER_HOUR" NUM - { - $$ = false - } -| "WITH" "MAX_UPDATES_PER_HOUR" NUM - { - $$ = false - } -| "WITH" "MAX_CONNECTIONS_PER_HOUR" NUM - { - $$ = false - } -| "WITH" "MAX_USER_CONNECTIONS" NUM - { - $$ = false - } - -PrivElem: - PrivType - { - $$ = &ast.PrivElem{ - Priv: $1.(mysql.PrivilegeType), - } - } -| PrivType '(' ColumnNameList ')' - { - $$ = &ast.PrivElem{ - Priv: $1.(mysql.PrivilegeType), - Cols: $3.([]*ast.ColumnName), - } - } - -PrivElemList: - PrivElem - { - $$ = []*ast.PrivElem{$1.(*ast.PrivElem)} - } -| PrivElemList ',' PrivElem - { - $$ = append($1.([]*ast.PrivElem), $3.(*ast.PrivElem)) - } - -PrivType: - "ALL" - { - $$ = mysql.AllPriv - } -| "ALL" "PRIVILEGES" - { - $$ = mysql.AllPriv - } -| "ALTER" - { - $$ = mysql.AlterPriv - } -| "CREATE" - { - $$ = mysql.CreatePriv - } -| "CREATE" "USER" - { - $$ = mysql.CreateUserPriv - } -| "TRIGGER" - { - $$ = mysql.TriggerPriv - } -| "DELETE" - { - $$ = mysql.DeletePriv - } -| "DROP" - { - $$ = mysql.DropPriv - } -| "PROCESS" - { - $$ = mysql.ProcessPriv - } -| "EXECUTE" - { - $$ = mysql.ExecutePriv - } -| "INDEX" - { - $$ = mysql.IndexPriv - } -| "INSERT" - { - $$ = mysql.InsertPriv - } -| "SELECT" - { - $$ = mysql.SelectPriv - } -| "SUPER" - { - $$ = mysql.SuperPriv - } -| "SHOW" "DATABASES" - { - $$ = mysql.ShowDBPriv - } -| "UPDATE" - { - $$ = mysql.UpdatePriv - } -| "GRANT" "OPTION" - { - $$ = mysql.GrantPriv - } -| "REFERENCES" - { - $$ = mysql.ReferencesPriv - } -| "REPLICATION" "SLAVE" - { - $$ = mysql.PrivilegeType(0) - } -| "REPLICATION" "CLIENT" - { - $$ = mysql.PrivilegeType(0) - } -| "USAGE" - { - $$ = mysql.PrivilegeType(0) - } -| "RELOAD" - { - $$ = mysql.PrivilegeType(0) - } -| "CREATE" "TEMPORARY" "TABLES" - { - $$ = mysql.PrivilegeType(0) - } -| "LOCK" "TABLES" - { - $$ = mysql.PrivilegeType(0) - } -| "CREATE" "VIEW" - { - $$ = mysql.PrivilegeType(0) - } -| "SHOW" "VIEW" - { - $$ = mysql.PrivilegeType(0) - } -| "CREATE" "ROUTINE" - { - $$ = mysql.PrivilegeType(0) - } -| "ALTER" "ROUTINE" - { - $$ = mysql.PrivilegeType(0) - } -| "EVENT" - { - $$ = mysql.PrivilegeType(0) - } - -ObjectType: - { - $$ = ast.ObjectTypeNone - } -| "TABLE" - { - $$ = ast.ObjectTypeTable - } - -PrivLevel: - '*' - { - $$ = &ast.GrantLevel { - Level: ast.GrantLevelDB, - } - } -| '*' '.' '*' - { - $$ = &ast.GrantLevel { - Level: ast.GrantLevelGlobal, - } - } -| Identifier '.' '*' - { - $$ = &ast.GrantLevel { - Level: ast.GrantLevelDB, - DBName: $1, - } - } -| Identifier '.' Identifier - { - $$ = &ast.GrantLevel { - Level: ast.GrantLevelTable, - DBName: $1, - TableName: $3, - } - } -| Identifier - { - $$ = &ast.GrantLevel { - Level: ast.GrantLevelTable, - TableName: $1, - } - } - -/**************************************RevokeStmt******************************************* - * See https://dev.mysql.com/doc/refman/5.7/en/revoke.html - *******************************************************************************************/ -RevokeStmt: - "REVOKE" PrivElemList "ON" ObjectType PrivLevel "FROM" UserSpecList - { - $$ = &ast.RevokeStmt{ - Privs: $2.([]*ast.PrivElem), - ObjectType: $4.(ast.ObjectTypeType), - Level: $5.(*ast.GrantLevel), - Users: $7.([]*ast.UserSpec), - } - } - -/**************************************LoadDataStmt***************************************** - * See https://dev.mysql.com/doc/refman/5.7/en/load-data.html - *******************************************************************************************/ -LoadDataStmt: - "LOAD" "DATA" LocalOpt "INFILE" stringLit "INTO" "TABLE" TableName CharsetOpt Fields Lines IgnoreLines ColumnNameListOptWithBrackets - { - x := &ast.LoadDataStmt{ - Path: $5, - Table: $8.(*ast.TableName), - Columns: $13.([]*ast.ColumnName), - IgnoreLines:$12.(uint64), - } - if $3 != nil { - x.IsLocal = true - } - if $10 != nil { - x.FieldsInfo = $10.(*ast.FieldsClause) - } - if $11 != nil { - x.LinesInfo = $11.(*ast.LinesClause) - } - $$ = x - } - -IgnoreLines: - { - $$ = uint64(0) - } -| "IGNORE" NUM "LINES" - { - $$ = getUint64FromNUM($2) - } - -CharsetOpt: - {} -| "CHARACTER" "SET" CharsetName - -LocalOpt: - { - $$ = nil - } -| "LOCAL" - { - $$ = $1 - } - -Fields: - { - escape := "\\" - $$ = &ast.FieldsClause{ - Terminated: "\t", - Escaped: escape[0], - } - } -| FieldsOrColumns FieldsTerminated Enclosed Escaped - { - escape := $4.(string) - if escape != "\\" && len(escape) > 1 { - yylex.Errorf("Incorrect arguments %s to ESCAPE", escape) - return 1 - } - var enclosed byte - str := $3.(string) - if len(str) > 1 { - yylex.Errorf("Incorrect arguments %s to ENCLOSED", escape) - return 1 - }else if len(str) != 0 { - enclosed = str[0] - } - var escaped byte - if len(escape) > 0 { - escaped = escape[0] - } - $$ = &ast.FieldsClause{ - Terminated: $2.(string), - Enclosed: enclosed, - Escaped: escaped, - } - } - -FieldsOrColumns: -"FIELDS" | "COLUMNS" - -FieldsTerminated: - { - $$ = "\t" - } -| "TERMINATED" "BY" stringLit - { - $$ = $3 - } - -Enclosed: - { - $$ = "" - } -| "ENCLOSED" "BY" stringLit - { - $$ = $3 - } - -Escaped: - { - $$ = "\\" - } -| "ESCAPED" "BY" stringLit - { - $$ = $3 - } - -Lines: - { - $$ = &ast.LinesClause{Terminated: "\n"} - } -| "LINES" Starting LinesTerminated - { - $$ = &ast.LinesClause{Starting: $2.(string), Terminated: $3.(string)} - } - -Starting: - { - $$ = "" - } -| "STARTING" "BY" stringLit - { - $$ = $3 - } - -LinesTerminated: - { - $$ = "\n" - } -| "TERMINATED" "BY" stringLit - { - $$ = $3 - } - - -/********************************************************************* - * Lock/Unlock Tables - * See http://dev.mysql.com/doc/refman/5.7/en/lock-tables.html - * All the statement leaves empty. This is used to prevent mysqldump error. - *********************************************************************/ - -UnlockTablesStmt: - "UNLOCK" TablesTerminalSym {} - -LockTablesStmt: - "LOCK" TablesTerminalSym TableLockList - {} - -TablesTerminalSym: - "TABLES" -| "TABLE" - -TableLock: - TableName LockType - -LockType: - "READ" -| "READ" "LOCAL" -| "WRITE" - -TableLockList: - TableLock -| TableLockList ',' TableLock - - -/******************************************************************** - * Kill Statement - * See https://dev.mysql.com/doc/refman/5.7/en/kill.html - *******************************************************************/ - -KillStmt: - KillOrKillTiDB NUM - { - $$ = &ast.KillStmt{ - ConnectionID: getUint64FromNUM($2), - TiDBExtension: $1.(bool), - } - } -| KillOrKillTiDB "CONNECTION" NUM - { - $$ = &ast.KillStmt{ - ConnectionID: getUint64FromNUM($3), - TiDBExtension: $1.(bool), - } - } -| KillOrKillTiDB "QUERY" NUM - { - $$ = &ast.KillStmt{ - ConnectionID: getUint64FromNUM($3), - Query: true, - TiDBExtension: $1.(bool), - } - } - -KillOrKillTiDB: - "KILL" - { - $$ = false - } -/* KILL TIDB is a special grammar extension in TiDB, it can be used only when - the client connect to TiDB directly, not proxied under LVS. */ -| "KILL" "TIDB" - { - $$ = true - } - -/*******************************************************************************************/ - -LoadStatsStmt: - "LOAD" "STATS" stringLit - { - $$ = &ast.LoadStatsStmt{ - Path: $3, - } - } - -%% diff --git a/parser/types/field_type.go b/parser/types/field_type.go deleted file mode 100644 index 810810e4001c3..0000000000000 --- a/parser/types/field_type.go +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "fmt" - "io" - "strings" - - "github.com/pingcap/tidb/mysql" - "github.com/pingcap/tidb/util/charset" - "github.com/pingcap/tidb/util/format" -) - -// UnspecifiedLength is unspecified length. -const ( - UnspecifiedLength = -1 -) - -// FieldType records field type information. -type FieldType struct { - Tp byte - Flag uint - Flen int - Decimal int - Charset string - Collate string - // Elems is the element list for enum and set type. - Elems []string -} - -// NewFieldType returns a FieldType, -// with a type and other information about field type. -func NewFieldType(tp byte) *FieldType { - return &FieldType{ - Tp: tp, - Flen: UnspecifiedLength, - Decimal: UnspecifiedLength, - } -} - -// Equal checks whether two FieldType objects are equal. -func (ft *FieldType) Equal(other *FieldType) bool { - // We do not need to compare whole `ft.Flag == other.Flag` when wrapping cast upon an Expression. - // but need compare unsigned_flag of ft.Flag. - partialEqual := ft.Tp == other.Tp && - ft.Flen == other.Flen && - ft.Decimal == other.Decimal && - ft.Charset == other.Charset && - ft.Collate == other.Collate && - mysql.HasUnsignedFlag(ft.Flag) == mysql.HasUnsignedFlag(other.Flag) - if !partialEqual || len(ft.Elems) != len(other.Elems) { - return false - } - for i := range ft.Elems { - if ft.Elems[i] != other.Elems[i] { - return false - } - } - return true -} - -// EvalType gets the type in evaluation. -func (ft *FieldType) EvalType() EvalType { - switch ft.Tp { - case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, - mysql.TypeBit, mysql.TypeYear: - return ETInt - case mysql.TypeFloat, mysql.TypeDouble: - return ETReal - case mysql.TypeNewDecimal: - return ETDecimal - case mysql.TypeDate, mysql.TypeDatetime: - return ETDatetime - case mysql.TypeTimestamp: - return ETTimestamp - case mysql.TypeDuration: - return ETDuration - case mysql.TypeJSON: - return ETJson - } - return ETString -} - -// Hybrid checks whether a type is a hybrid type, which can represent different types of value in specific context. -func (ft *FieldType) Hybrid() bool { - return ft.Tp == mysql.TypeEnum || ft.Tp == mysql.TypeBit || ft.Tp == mysql.TypeSet -} - -// Init initializes the FieldType data. -func (ft *FieldType) Init(tp byte) { - ft.Tp = tp - ft.Flen = UnspecifiedLength - ft.Decimal = UnspecifiedLength -} - -// CompactStr only considers Tp/CharsetBin/Flen/Deimal. -// This is used for showing column type in infoschema. -func (ft *FieldType) CompactStr() string { - ts := TypeToStr(ft.Tp, ft.Charset) - suffix := "" - - defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimal(ft.Tp) - isDecimalNotDefault := ft.Decimal != defaultDecimal && ft.Decimal != 0 && ft.Decimal != UnspecifiedLength - - // displayFlen and displayDecimal are flen and decimal values with `-1` substituted with default value. - displayFlen, displayDecimal := ft.Flen, ft.Decimal - if displayFlen == 0 || displayFlen == UnspecifiedLength { - displayFlen = defaultFlen - } - if displayDecimal == 0 || displayDecimal == UnspecifiedLength { - displayDecimal = defaultDecimal - } - - switch ft.Tp { - case mysql.TypeEnum, mysql.TypeSet: - // Format is ENUM ('e1', 'e2') or SET ('e1', 'e2') - es := make([]string, 0, len(ft.Elems)) - for _, e := range ft.Elems { - e = format.OutputFormat(e) - es = append(es, e) - } - suffix = fmt.Sprintf("('%s')", strings.Join(es, "','")) - case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDuration: - if isDecimalNotDefault { - suffix = fmt.Sprintf("(%d)", displayDecimal) - } - case mysql.TypeDouble, mysql.TypeFloat: - // 1. Flen Not Default, Decimal Not Default -> Valid - // 2. Flen Not Default, Decimal Default (-1) -> Invalid - // 3. Flen Default, Decimal Not Default -> Valid - // 4. Flen Default, Decimal Default -> Valid (hide) - if isDecimalNotDefault { - suffix = fmt.Sprintf("(%d,%d)", displayFlen, displayDecimal) - } - case mysql.TypeNewDecimal: - suffix = fmt.Sprintf("(%d,%d)", displayFlen, displayDecimal) - case mysql.TypeBit, mysql.TypeShort, mysql.TypeTiny, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeString, mysql.TypeVarString: - // Flen is always shown. - suffix = fmt.Sprintf("(%d)", displayFlen) - } - return ts + suffix -} - -// InfoSchemaStr joins the CompactStr with unsigned flag and -// returns a string. -func (ft *FieldType) InfoSchemaStr() string { - suffix := "" - if mysql.HasUnsignedFlag(ft.Flag) { - suffix = " unsigned" - } - return ft.CompactStr() + suffix -} - -// String joins the information of FieldType and returns a string. -// Note: when flen or decimal is unspecified, this function will use the default value instead of -1. -func (ft *FieldType) String() string { - strs := []string{ft.CompactStr()} - if mysql.HasUnsignedFlag(ft.Flag) { - strs = append(strs, "UNSIGNED") - } - if mysql.HasZerofillFlag(ft.Flag) { - strs = append(strs, "ZEROFILL") - } - if mysql.HasBinaryFlag(ft.Flag) && ft.Tp != mysql.TypeString { - strs = append(strs, "BINARY") - } - - if IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp) { - if ft.Charset != "" && ft.Charset != charset.CharsetBin { - strs = append(strs, fmt.Sprintf("CHARACTER SET %s", ft.Charset)) - } - if ft.Collate != "" && ft.Collate != charset.CharsetBin { - strs = append(strs, fmt.Sprintf("COLLATE %s", ft.Collate)) - } - } - - return strings.Join(strs, " ") -} - -// FormatAsCastType is used for write AST back to string. -func (ft *FieldType) FormatAsCastType(w io.Writer) { - switch ft.Tp { - case mysql.TypeVarString: - if ft.Charset == charset.CharsetBin && ft.Collate == charset.CollationBin { - fmt.Fprint(w, "BINARY") - } else { - fmt.Fprint(w, "CHAR") - } - if ft.Flen != UnspecifiedLength { - fmt.Fprintf(w, "(%d)", ft.Flen) - } - if ft.Flag&mysql.BinaryFlag != 0 { - fmt.Fprint(w, " BINARY") - } - if ft.Charset != charset.CharsetBin && ft.Charset != mysql.DefaultCharset { - fmt.Fprintf(w, " %s", ft.Charset) - } - case mysql.TypeDate: - fmt.Fprint(w, "DATE") - case mysql.TypeDatetime: - fmt.Fprint(w, "DATETIME") - if ft.Decimal > 0 { - fmt.Fprintf(w, "(%d)", ft.Decimal) - } - case mysql.TypeNewDecimal: - fmt.Fprint(w, "DECIMAL") - if ft.Flen > 0 && ft.Decimal > 0 { - fmt.Fprintf(w, "(%d, %d)", ft.Flen, ft.Decimal) - } else if ft.Flen > 0 { - fmt.Fprintf(w, "(%d)", ft.Flen) - } - case mysql.TypeDuration: - fmt.Fprint(w, "TIME") - if ft.Decimal > 0 { - fmt.Fprintf(w, "(%d)", ft.Decimal) - } - case mysql.TypeLonglong: - if ft.Flag&mysql.UnsignedFlag != 0 { - fmt.Fprint(w, "UNSIGNED") - } else { - fmt.Fprint(w, "SIGNED") - } - case mysql.TypeJSON: - fmt.Fprint(w, "JSON") - } -} - -// VarStorageLen indicates this column is a variable length column. -const VarStorageLen = -1 - -// StorageLength is the length of stored value for the type. -func (ft *FieldType) StorageLength() int { - switch ft.Tp { - case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, - mysql.TypeLonglong, mysql.TypeDouble, mysql.TypeFloat, mysql.TypeYear, mysql.TypeDuration, - mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp, mysql.TypeEnum, mysql.TypeSet, - mysql.TypeBit: - // This may not be the accurate length, because we may encode them as varint. - return 8 - case mysql.TypeNewDecimal: - precision, frac := ft.Flen-ft.Decimal, ft.Decimal - return precision/digitsPerWord*wordSize + dig2bytes[precision%digitsPerWord] + frac/digitsPerWord*wordSize + dig2bytes[frac%digitsPerWord] - default: - return VarStorageLen - } -} From a7e2183c805611f27ec4b28d97e0409e312f3c22 Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 5 Nov 2018 17:22:15 +0800 Subject: [PATCH 04/11] remove util/charset --- util/charset/charset.go | 422 ---------------------------------------- 1 file changed, 422 deletions(-) delete mode 100644 util/charset/charset.go diff --git a/util/charset/charset.go b/util/charset/charset.go deleted file mode 100644 index 7d0ec7e3e2f85..0000000000000 --- a/util/charset/charset.go +++ /dev/null @@ -1,422 +0,0 @@ -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package charset - -import ( - "strings" - - "github.com/pingcap/tidb/mysql" - "github.com/pkg/errors" -) - -// Charset is a charset. -// Now we only support MySQL. -type Charset struct { - Name string - DefaultCollation string - Collations map[string]*Collation - Desc string - Maxlen int -} - -// Collation is a collation. -// Now we only support MySQL. -type Collation struct { - ID int - CharsetName string - Name string - IsDefault bool -} - -var charsets = make(map[string]*Charset) - -// All the supported charsets should be in the following table. -var charsetInfos = []*Charset{ - {CharsetUTF8, CollationUTF8, make(map[string]*Collation), "UTF-8 Unicode", 3}, - {CharsetUTF8MB4, CollationUTF8MB4, make(map[string]*Collation), "UTF-8 Unicode", 4}, - {CharsetASCII, CollationASCII, make(map[string]*Collation), "US ASCII", 1}, - {CharsetLatin1, CollationLatin1, make(map[string]*Collation), "Latin1", 1}, - {CharsetBin, CollationBin, make(map[string]*Collation), "binary", 1}, -} - -// Desc is a charset description. -type Desc struct { - Name string - Desc string - DefaultCollation string - Maxlen int -} - -// GetAllCharsets gets all charset descriptions in the local charsets. -func GetAllCharsets() []*Desc { - descs := make([]*Desc, 0, len(charsets)) - // The charsetInfos is an array, so the iterate order will be stable. - for _, ci := range charsetInfos { - c, ok := charsets[ci.Name] - if !ok { - continue - } - desc := &Desc{ - Name: c.Name, - DefaultCollation: c.DefaultCollation, - Desc: c.Desc, - Maxlen: c.Maxlen, - } - descs = append(descs, desc) - } - return descs -} - -// ValidCharsetAndCollation checks the charset and the collation validity -// and returns a boolean. -func ValidCharsetAndCollation(cs string, co string) bool { - // We will use utf8 as a default charset. - if cs == "" { - cs = "utf8" - } - cs = strings.ToLower(cs) - c, ok := charsets[cs] - if !ok { - return false - } - - if co == "" { - return true - } - _, ok = c.Collations[co] - if !ok { - return false - } - - return true -} - -// GetDefaultCollation returns the default collation for charset. -func GetDefaultCollation(charset string) (string, error) { - charset = strings.ToLower(charset) - if charset == CharsetBin { - return CollationBin, nil - } - c, ok := charsets[charset] - if !ok { - return "", errors.Errorf("Unknown charset %s", charset) - } - return c.DefaultCollation, nil -} - -// GetDefaultCharsetAndCollate returns the default charset and collation. -func GetDefaultCharsetAndCollate() (string, string) { - return mysql.DefaultCharset, mysql.DefaultCollationName -} - -// GetCharsetInfo returns charset and collation for cs as name. -func GetCharsetInfo(cs string) (string, string, error) { - c, ok := charsets[strings.ToLower(cs)] - if !ok { - return "", "", errors.Errorf("Unknown charset %s", cs) - } - return c.Name, c.DefaultCollation, nil -} - -// GetCharsetDesc gets charset descriptions in the local charsets. -func GetCharsetDesc(cs string) (*Desc, error) { - c, ok := charsets[strings.ToLower(cs)] - if !ok { - return nil, errors.Errorf("Unknown charset %s", cs) - } - desc := &Desc{ - Name: c.Name, - DefaultCollation: c.DefaultCollation, - Desc: c.Desc, - Maxlen: c.Maxlen, - } - return desc, nil -} - -// GetCharsetInfoByID returns charset and collation for id as cs_number. -func GetCharsetInfoByID(coID int) (string, string, error) { - if coID == mysql.DefaultCollationID { - return mysql.DefaultCharset, mysql.DefaultCollationName, nil - } - for _, collation := range collations { - if coID == collation.ID { - return collation.CharsetName, collation.Name, nil - } - } - return "", "", errors.Errorf("Unknown charset id %d", coID) -} - -// GetCollations returns a list for all collations. -func GetCollations() []*Collation { - return collations -} - -const ( - // CharsetBin is used for marking binary charset. - CharsetBin = "binary" - // CollationBin is the default collation for CharsetBin. - CollationBin = "binary" - // CharsetUTF8 is the default charset for string types. - CharsetUTF8 = "utf8" - // CollationUTF8 is the default collation for CharsetUTF8. - CollationUTF8 = "utf8_bin" - // CharsetUTF8MB4 represents 4 bytes utf8, which works the same way as utf8 in Go. - CharsetUTF8MB4 = "utf8mb4" - // CollationUTF8MB4 is the default collation for CharsetUTF8MB4. - CollationUTF8MB4 = "utf8mb4_bin" - // CharsetASCII is a subset of UTF8. - CharsetASCII = "ascii" - // CollationASCII is the default collation for CharsetACSII. - CollationASCII = "ascii_bin" - // CharsetLatin1 is a single byte charset. - CharsetLatin1 = "latin1" - // CollationLatin1 is the default collation for CharsetLatin1. - CollationLatin1 = "latin1_bin" -) - -var collations = []*Collation{ - {1, "big5", "big5_chinese_ci", true}, - {2, "latin2", "latin2_czech_cs", false}, - {3, "dec8", "dec8_swedish_ci", true}, - {4, "cp850", "cp850_general_ci", true}, - {5, "latin1", "latin1_german1_ci", false}, - {6, "hp8", "hp8_english_ci", true}, - {7, "koi8r", "koi8r_general_ci", true}, - {8, "latin1", "latin1_swedish_ci", true}, - {9, "latin2", "latin2_general_ci", true}, - {10, "swe7", "swe7_swedish_ci", true}, - {11, "ascii", "ascii_general_ci", true}, - {12, "ujis", "ujis_japanese_ci", true}, - {13, "sjis", "sjis_japanese_ci", true}, - {14, "cp1251", "cp1251_bulgarian_ci", false}, - {15, "latin1", "latin1_danish_ci", false}, - {16, "hebrew", "hebrew_general_ci", true}, - {18, "tis620", "tis620_thai_ci", true}, - {19, "euckr", "euckr_korean_ci", true}, - {20, "latin7", "latin7_estonian_cs", false}, - {21, "latin2", "latin2_hungarian_ci", false}, - {22, "koi8u", "koi8u_general_ci", true}, - {23, "cp1251", "cp1251_ukrainian_ci", false}, - {24, "gb2312", "gb2312_chinese_ci", true}, - {25, "greek", "greek_general_ci", true}, - {26, "cp1250", "cp1250_general_ci", true}, - {27, "latin2", "latin2_croatian_ci", false}, - {28, "gbk", "gbk_chinese_ci", true}, - {29, "cp1257", "cp1257_lithuanian_ci", false}, - {30, "latin5", "latin5_turkish_ci", true}, - {31, "latin1", "latin1_german2_ci", false}, - {32, "armscii8", "armscii8_general_ci", true}, - {33, "utf8", "utf8_general_ci", true}, - {34, "cp1250", "cp1250_czech_cs", false}, - {35, "ucs2", "ucs2_general_ci", true}, - {36, "cp866", "cp866_general_ci", true}, - {37, "keybcs2", "keybcs2_general_ci", true}, - {38, "macce", "macce_general_ci", true}, - {39, "macroman", "macroman_general_ci", true}, - {40, "cp852", "cp852_general_ci", true}, - {41, "latin7", "latin7_general_ci", true}, - {42, "latin7", "latin7_general_cs", false}, - {43, "macce", "macce_bin", false}, - {44, "cp1250", "cp1250_croatian_ci", false}, - {45, "utf8mb4", "utf8mb4_general_ci", true}, - {46, "utf8mb4", "utf8mb4_bin", false}, - {47, "latin1", "latin1_bin", false}, - {48, "latin1", "latin1_general_ci", false}, - {49, "latin1", "latin1_general_cs", false}, - {50, "cp1251", "cp1251_bin", false}, - {51, "cp1251", "cp1251_general_ci", true}, - {52, "cp1251", "cp1251_general_cs", false}, - {53, "macroman", "macroman_bin", false}, - {54, "utf16", "utf16_general_ci", true}, - {55, "utf16", "utf16_bin", false}, - {56, "utf16le", "utf16le_general_ci", true}, - {57, "cp1256", "cp1256_general_ci", true}, - {58, "cp1257", "cp1257_bin", false}, - {59, "cp1257", "cp1257_general_ci", true}, - {60, "utf32", "utf32_general_ci", true}, - {61, "utf32", "utf32_bin", false}, - {62, "utf16le", "utf16le_bin", false}, - {63, "binary", "binary", true}, - {64, "armscii8", "armscii8_bin", false}, - {65, "ascii", "ascii_bin", false}, - {66, "cp1250", "cp1250_bin", false}, - {67, "cp1256", "cp1256_bin", false}, - {68, "cp866", "cp866_bin", false}, - {69, "dec8", "dec8_bin", false}, - {70, "greek", "greek_bin", false}, - {71, "hebrew", "hebrew_bin", false}, - {72, "hp8", "hp8_bin", false}, - {73, "keybcs2", "keybcs2_bin", false}, - {74, "koi8r", "koi8r_bin", false}, - {75, "koi8u", "koi8u_bin", false}, - {77, "latin2", "latin2_bin", false}, - {78, "latin5", "latin5_bin", false}, - {79, "latin7", "latin7_bin", false}, - {80, "cp850", "cp850_bin", false}, - {81, "cp852", "cp852_bin", false}, - {82, "swe7", "swe7_bin", false}, - {83, "utf8", "utf8_bin", false}, - {84, "big5", "big5_bin", false}, - {85, "euckr", "euckr_bin", false}, - {86, "gb2312", "gb2312_bin", false}, - {87, "gbk", "gbk_bin", false}, - {88, "sjis", "sjis_bin", false}, - {89, "tis620", "tis620_bin", false}, - {90, "ucs2", "ucs2_bin", false}, - {91, "ujis", "ujis_bin", false}, - {92, "geostd8", "geostd8_general_ci", true}, - {93, "geostd8", "geostd8_bin", false}, - {94, "latin1", "latin1_spanish_ci", false}, - {95, "cp932", "cp932_japanese_ci", true}, - {96, "cp932", "cp932_bin", false}, - {97, "eucjpms", "eucjpms_japanese_ci", true}, - {98, "eucjpms", "eucjpms_bin", false}, - {99, "cp1250", "cp1250_polish_ci", false}, - {101, "utf16", "utf16_unicode_ci", false}, - {102, "utf16", "utf16_icelandic_ci", false}, - {103, "utf16", "utf16_latvian_ci", false}, - {104, "utf16", "utf16_romanian_ci", false}, - {105, "utf16", "utf16_slovenian_ci", false}, - {106, "utf16", "utf16_polish_ci", false}, - {107, "utf16", "utf16_estonian_ci", false}, - {108, "utf16", "utf16_spanish_ci", false}, - {109, "utf16", "utf16_swedish_ci", false}, - {110, "utf16", "utf16_turkish_ci", false}, - {111, "utf16", "utf16_czech_ci", false}, - {112, "utf16", "utf16_danish_ci", false}, - {113, "utf16", "utf16_lithuanian_ci", false}, - {114, "utf16", "utf16_slovak_ci", false}, - {115, "utf16", "utf16_spanish2_ci", false}, - {116, "utf16", "utf16_roman_ci", false}, - {117, "utf16", "utf16_persian_ci", false}, - {118, "utf16", "utf16_esperanto_ci", false}, - {119, "utf16", "utf16_hungarian_ci", false}, - {120, "utf16", "utf16_sinhala_ci", false}, - {121, "utf16", "utf16_german2_ci", false}, - {122, "utf16", "utf16_croatian_ci", false}, - {123, "utf16", "utf16_unicode_520_ci", false}, - {124, "utf16", "utf16_vietnamese_ci", false}, - {128, "ucs2", "ucs2_unicode_ci", false}, - {129, "ucs2", "ucs2_icelandic_ci", false}, - {130, "ucs2", "ucs2_latvian_ci", false}, - {131, "ucs2", "ucs2_romanian_ci", false}, - {132, "ucs2", "ucs2_slovenian_ci", false}, - {133, "ucs2", "ucs2_polish_ci", false}, - {134, "ucs2", "ucs2_estonian_ci", false}, - {135, "ucs2", "ucs2_spanish_ci", false}, - {136, "ucs2", "ucs2_swedish_ci", false}, - {137, "ucs2", "ucs2_turkish_ci", false}, - {138, "ucs2", "ucs2_czech_ci", false}, - {139, "ucs2", "ucs2_danish_ci", false}, - {140, "ucs2", "ucs2_lithuanian_ci", false}, - {141, "ucs2", "ucs2_slovak_ci", false}, - {142, "ucs2", "ucs2_spanish2_ci", false}, - {143, "ucs2", "ucs2_roman_ci", false}, - {144, "ucs2", "ucs2_persian_ci", false}, - {145, "ucs2", "ucs2_esperanto_ci", false}, - {146, "ucs2", "ucs2_hungarian_ci", false}, - {147, "ucs2", "ucs2_sinhala_ci", false}, - {148, "ucs2", "ucs2_german2_ci", false}, - {149, "ucs2", "ucs2_croatian_ci", false}, - {150, "ucs2", "ucs2_unicode_520_ci", false}, - {151, "ucs2", "ucs2_vietnamese_ci", false}, - {159, "ucs2", "ucs2_general_mysql500_ci", false}, - {160, "utf32", "utf32_unicode_ci", false}, - {161, "utf32", "utf32_icelandic_ci", false}, - {162, "utf32", "utf32_latvian_ci", false}, - {163, "utf32", "utf32_romanian_ci", false}, - {164, "utf32", "utf32_slovenian_ci", false}, - {165, "utf32", "utf32_polish_ci", false}, - {166, "utf32", "utf32_estonian_ci", false}, - {167, "utf32", "utf32_spanish_ci", false}, - {168, "utf32", "utf32_swedish_ci", false}, - {169, "utf32", "utf32_turkish_ci", false}, - {170, "utf32", "utf32_czech_ci", false}, - {171, "utf32", "utf32_danish_ci", false}, - {172, "utf32", "utf32_lithuanian_ci", false}, - {173, "utf32", "utf32_slovak_ci", false}, - {174, "utf32", "utf32_spanish2_ci", false}, - {175, "utf32", "utf32_roman_ci", false}, - {176, "utf32", "utf32_persian_ci", false}, - {177, "utf32", "utf32_esperanto_ci", false}, - {178, "utf32", "utf32_hungarian_ci", false}, - {179, "utf32", "utf32_sinhala_ci", false}, - {180, "utf32", "utf32_german2_ci", false}, - {181, "utf32", "utf32_croatian_ci", false}, - {182, "utf32", "utf32_unicode_520_ci", false}, - {183, "utf32", "utf32_vietnamese_ci", false}, - {192, "utf8", "utf8_unicode_ci", false}, - {193, "utf8", "utf8_icelandic_ci", false}, - {194, "utf8", "utf8_latvian_ci", false}, - {195, "utf8", "utf8_romanian_ci", false}, - {196, "utf8", "utf8_slovenian_ci", false}, - {197, "utf8", "utf8_polish_ci", false}, - {198, "utf8", "utf8_estonian_ci", false}, - {199, "utf8", "utf8_spanish_ci", false}, - {200, "utf8", "utf8_swedish_ci", false}, - {201, "utf8", "utf8_turkish_ci", false}, - {202, "utf8", "utf8_czech_ci", false}, - {203, "utf8", "utf8_danish_ci", false}, - {204, "utf8", "utf8_lithuanian_ci", false}, - {205, "utf8", "utf8_slovak_ci", false}, - {206, "utf8", "utf8_spanish2_ci", false}, - {207, "utf8", "utf8_roman_ci", false}, - {208, "utf8", "utf8_persian_ci", false}, - {209, "utf8", "utf8_esperanto_ci", false}, - {210, "utf8", "utf8_hungarian_ci", false}, - {211, "utf8", "utf8_sinhala_ci", false}, - {212, "utf8", "utf8_german2_ci", false}, - {213, "utf8", "utf8_croatian_ci", false}, - {214, "utf8", "utf8_unicode_520_ci", false}, - {215, "utf8", "utf8_vietnamese_ci", false}, - {223, "utf8", "utf8_general_mysql500_ci", false}, - {224, "utf8mb4", "utf8mb4_unicode_ci", false}, - {225, "utf8mb4", "utf8mb4_icelandic_ci", false}, - {226, "utf8mb4", "utf8mb4_latvian_ci", false}, - {227, "utf8mb4", "utf8mb4_romanian_ci", false}, - {228, "utf8mb4", "utf8mb4_slovenian_ci", false}, - {229, "utf8mb4", "utf8mb4_polish_ci", false}, - {230, "utf8mb4", "utf8mb4_estonian_ci", false}, - {231, "utf8mb4", "utf8mb4_spanish_ci", false}, - {232, "utf8mb4", "utf8mb4_swedish_ci", false}, - {233, "utf8mb4", "utf8mb4_turkish_ci", false}, - {234, "utf8mb4", "utf8mb4_czech_ci", false}, - {235, "utf8mb4", "utf8mb4_danish_ci", false}, - {236, "utf8mb4", "utf8mb4_lithuanian_ci", false}, - {237, "utf8mb4", "utf8mb4_slovak_ci", false}, - {238, "utf8mb4", "utf8mb4_spanish2_ci", false}, - {239, "utf8mb4", "utf8mb4_roman_ci", false}, - {240, "utf8mb4", "utf8mb4_persian_ci", false}, - {241, "utf8mb4", "utf8mb4_esperanto_ci", false}, - {242, "utf8mb4", "utf8mb4_hungarian_ci", false}, - {243, "utf8mb4", "utf8mb4_sinhala_ci", false}, - {244, "utf8mb4", "utf8mb4_german2_ci", false}, - {245, "utf8mb4", "utf8mb4_croatian_ci", false}, - {246, "utf8mb4", "utf8mb4_unicode_520_ci", false}, - {247, "utf8mb4", "utf8mb4_vietnamese_ci", false}, -} - -// init method always puts to the end of file. -func init() { - for _, c := range charsetInfos { - charsets[c.Name] = c - } - for _, c := range collations { - charset, ok := charsets[c.CharsetName] - if !ok { - continue - } - charset.Collations[c.Name] = c - } -} From 2ae3370d7f2e500bc7665bf919c8a7f93d516046 Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 5 Nov 2018 17:23:19 +0800 Subject: [PATCH 05/11] remove mysql --- mysql/charset.go | 610 ----------------------------------------------- 1 file changed, 610 deletions(-) delete mode 100644 mysql/charset.go diff --git a/mysql/charset.go b/mysql/charset.go deleted file mode 100644 index f2e99a43765ef..0000000000000 --- a/mysql/charset.go +++ /dev/null @@ -1,610 +0,0 @@ -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package mysql - -import "unicode" - -// CharsetIDs maps charset name to its default collation ID. -var CharsetIDs = map[string]uint8{ - "big5": 1, - "dec8": 3, - "cp850": 4, - "hp8": 6, - "koi8r": 7, - "latin1": 8, - "latin2": 9, - "swe7": 10, - "ascii": 11, - "ujis": 12, - "sjis": 13, - "hebrew": 16, - "tis620": 18, - "euckr": 19, - "koi8u": 22, - "gb2312": 24, - "greek": 25, - "cp1250": 26, - "gbk": 28, - "latin5": 30, - "armscii8": 32, - "utf8": 33, - "ucs2": 35, - "cp866": 36, - "keybcs2": 37, - "macce": 38, - "macroman": 39, - "cp852": 40, - "latin7": 41, - "utf8mb4": 45, - "cp1251": 51, - "utf16": 54, - "utf16le": 56, - "cp1256": 57, - "cp1257": 59, - "utf32": 60, - "binary": 63, - "geostd8": 92, - "cp932": 95, - "eucjpms": 97, -} - -// Charsets maps charset name to its default collation name. -var Charsets = map[string]string{ - "big5": "big5_chinese_ci", - "dec8": "dec8_swedish_ci", - "cp850": "cp850_general_ci", - "hp8": "hp8_english_ci", - "koi8r": "koi8r_general_ci", - "latin1": "latin1_swedish_ci", - "latin2": "latin2_general_ci", - "swe7": "swe7_swedish_ci", - "ascii": "ascii_general_ci", - "ujis": "ujis_japanese_ci", - "sjis": "sjis_japanese_ci", - "hebrew": "hebrew_general_ci", - "tis620": "tis620_thai_ci", - "euckr": "euckr_korean_ci", - "koi8u": "koi8u_general_ci", - "gb2312": "gb2312_chinese_ci", - "greek": "greek_general_ci", - "cp1250": "cp1250_general_ci", - "gbk": "gbk_chinese_ci", - "latin5": "latin5_turkish_ci", - "armscii8": "armscii8_general_ci", - "utf8": "utf8_general_ci", - "ucs2": "ucs2_general_ci", - "cp866": "cp866_general_ci", - "keybcs2": "keybcs2_general_ci", - "macce": "macce_general_ci", - "macroman": "macroman_general_ci", - "cp852": "cp852_general_ci", - "latin7": "latin7_general_ci", - "utf8mb4": "utf8mb4_general_ci", - "cp1251": "cp1251_general_ci", - "utf16": "utf16_general_ci", - "utf16le": "utf16le_general_ci", - "cp1256": "cp1256_general_ci", - "cp1257": "cp1257_general_ci", - "utf32": "utf32_general_ci", - "binary": "binary", - "geostd8": "geostd8_general_ci", - "cp932": "cp932_japanese_ci", - "eucjpms": "eucjpms_japanese_ci", -} - -// Collations maps MySQL default collation ID to its name. -var Collations = map[uint8]string{ - 1: "big5_chinese_ci", - 2: "latin2_czech_cs", - 3: "dec8_swedish_ci", - 4: "cp850_general_ci", - 5: "latin1_german1_ci", - 6: "hp8_english_ci", - 7: "koi8r_general_ci", - 8: "latin1_swedish_ci", - 9: "latin2_general_ci", - 10: "swe7_swedish_ci", - 11: "ascii_general_ci", - 12: "ujis_japanese_ci", - 13: "sjis_japanese_ci", - 14: "cp1251_bulgarian_ci", - 15: "latin1_danish_ci", - 16: "hebrew_general_ci", - 18: "tis620_thai_ci", - 19: "euckr_korean_ci", - 20: "latin7_estonian_cs", - 21: "latin2_hungarian_ci", - 22: "koi8u_general_ci", - 23: "cp1251_ukrainian_ci", - 24: "gb2312_chinese_ci", - 25: "greek_general_ci", - 26: "cp1250_general_ci", - 27: "latin2_croatian_ci", - 28: "gbk_chinese_ci", - 29: "cp1257_lithuanian_ci", - 30: "latin5_turkish_ci", - 31: "latin1_german2_ci", - 32: "armscii8_general_ci", - 33: "utf8_general_ci", - 34: "cp1250_czech_cs", - 35: "ucs2_general_ci", - 36: "cp866_general_ci", - 37: "keybcs2_general_ci", - 38: "macce_general_ci", - 39: "macroman_general_ci", - 40: "cp852_general_ci", - 41: "latin7_general_ci", - 42: "latin7_general_cs", - 43: "macce_bin", - 44: "cp1250_croatian_ci", - 45: "utf8mb4_general_ci", - 46: "utf8mb4_bin", - 47: "latin1_bin", - 48: "latin1_general_ci", - 49: "latin1_general_cs", - 50: "cp1251_bin", - 51: "cp1251_general_ci", - 52: "cp1251_general_cs", - 53: "macroman_bin", - 54: "utf16_general_ci", - 55: "utf16_bin", - 56: "utf16le_general_ci", - 57: "cp1256_general_ci", - 58: "cp1257_bin", - 59: "cp1257_general_ci", - 60: "utf32_general_ci", - 61: "utf32_bin", - 62: "utf16le_bin", - 63: "binary", - 64: "armscii8_bin", - 65: "ascii_bin", - 66: "cp1250_bin", - 67: "cp1256_bin", - 68: "cp866_bin", - 69: "dec8_bin", - 70: "greek_bin", - 71: "hebrew_bin", - 72: "hp8_bin", - 73: "keybcs2_bin", - 74: "koi8r_bin", - 75: "koi8u_bin", - 77: "latin2_bin", - 78: "latin5_bin", - 79: "latin7_bin", - 80: "cp850_bin", - 81: "cp852_bin", - 82: "swe7_bin", - 83: "utf8_bin", - 84: "big5_bin", - 85: "euckr_bin", - 86: "gb2312_bin", - 87: "gbk_bin", - 88: "sjis_bin", - 89: "tis620_bin", - 90: "ucs2_bin", - 91: "ujis_bin", - 92: "geostd8_general_ci", - 93: "geostd8_bin", - 94: "latin1_spanish_ci", - 95: "cp932_japanese_ci", - 96: "cp932_bin", - 97: "eucjpms_japanese_ci", - 98: "eucjpms_bin", - 99: "cp1250_polish_ci", - 101: "utf16_unicode_ci", - 102: "utf16_icelandic_ci", - 103: "utf16_latvian_ci", - 104: "utf16_romanian_ci", - 105: "utf16_slovenian_ci", - 106: "utf16_polish_ci", - 107: "utf16_estonian_ci", - 108: "utf16_spanish_ci", - 109: "utf16_swedish_ci", - 110: "utf16_turkish_ci", - 111: "utf16_czech_ci", - 112: "utf16_danish_ci", - 113: "utf16_lithuanian_ci", - 114: "utf16_slovak_ci", - 115: "utf16_spanish2_ci", - 116: "utf16_roman_ci", - 117: "utf16_persian_ci", - 118: "utf16_esperanto_ci", - 119: "utf16_hungarian_ci", - 120: "utf16_sinhala_ci", - 121: "utf16_german2_ci", - 122: "utf16_croatian_ci", - 123: "utf16_unicode_520_ci", - 124: "utf16_vietnamese_ci", - 128: "ucs2_unicode_ci", - 129: "ucs2_icelandic_ci", - 130: "ucs2_latvian_ci", - 131: "ucs2_romanian_ci", - 132: "ucs2_slovenian_ci", - 133: "ucs2_polish_ci", - 134: "ucs2_estonian_ci", - 135: "ucs2_spanish_ci", - 136: "ucs2_swedish_ci", - 137: "ucs2_turkish_ci", - 138: "ucs2_czech_ci", - 139: "ucs2_danish_ci", - 140: "ucs2_lithuanian_ci", - 141: "ucs2_slovak_ci", - 142: "ucs2_spanish2_ci", - 143: "ucs2_roman_ci", - 144: "ucs2_persian_ci", - 145: "ucs2_esperanto_ci", - 146: "ucs2_hungarian_ci", - 147: "ucs2_sinhala_ci", - 148: "ucs2_german2_ci", - 149: "ucs2_croatian_ci", - 150: "ucs2_unicode_520_ci", - 151: "ucs2_vietnamese_ci", - 159: "ucs2_general_mysql500_ci", - 160: "utf32_unicode_ci", - 161: "utf32_icelandic_ci", - 162: "utf32_latvian_ci", - 163: "utf32_romanian_ci", - 164: "utf32_slovenian_ci", - 165: "utf32_polish_ci", - 166: "utf32_estonian_ci", - 167: "utf32_spanish_ci", - 168: "utf32_swedish_ci", - 169: "utf32_turkish_ci", - 170: "utf32_czech_ci", - 171: "utf32_danish_ci", - 172: "utf32_lithuanian_ci", - 173: "utf32_slovak_ci", - 174: "utf32_spanish2_ci", - 175: "utf32_roman_ci", - 176: "utf32_persian_ci", - 177: "utf32_esperanto_ci", - 178: "utf32_hungarian_ci", - 179: "utf32_sinhala_ci", - 180: "utf32_german2_ci", - 181: "utf32_croatian_ci", - 182: "utf32_unicode_520_ci", - 183: "utf32_vietnamese_ci", - 192: "utf8_unicode_ci", - 193: "utf8_icelandic_ci", - 194: "utf8_latvian_ci", - 195: "utf8_romanian_ci", - 196: "utf8_slovenian_ci", - 197: "utf8_polish_ci", - 198: "utf8_estonian_ci", - 199: "utf8_spanish_ci", - 200: "utf8_swedish_ci", - 201: "utf8_turkish_ci", - 202: "utf8_czech_ci", - 203: "utf8_danish_ci", - 204: "utf8_lithuanian_ci", - 205: "utf8_slovak_ci", - 206: "utf8_spanish2_ci", - 207: "utf8_roman_ci", - 208: "utf8_persian_ci", - 209: "utf8_esperanto_ci", - 210: "utf8_hungarian_ci", - 211: "utf8_sinhala_ci", - 212: "utf8_german2_ci", - 213: "utf8_croatian_ci", - 214: "utf8_unicode_520_ci", - 215: "utf8_vietnamese_ci", - 223: "utf8_general_mysql500_ci", - 224: "utf8mb4_unicode_ci", - 225: "utf8mb4_icelandic_ci", - 226: "utf8mb4_latvian_ci", - 227: "utf8mb4_romanian_ci", - 228: "utf8mb4_slovenian_ci", - 229: "utf8mb4_polish_ci", - 230: "utf8mb4_estonian_ci", - 231: "utf8mb4_spanish_ci", - 232: "utf8mb4_swedish_ci", - 233: "utf8mb4_turkish_ci", - 234: "utf8mb4_czech_ci", - 235: "utf8mb4_danish_ci", - 236: "utf8mb4_lithuanian_ci", - 237: "utf8mb4_slovak_ci", - 238: "utf8mb4_spanish2_ci", - 239: "utf8mb4_roman_ci", - 240: "utf8mb4_persian_ci", - 241: "utf8mb4_esperanto_ci", - 242: "utf8mb4_hungarian_ci", - 243: "utf8mb4_sinhala_ci", - 244: "utf8mb4_german2_ci", - 245: "utf8mb4_croatian_ci", - 246: "utf8mb4_unicode_520_ci", - 247: "utf8mb4_vietnamese_ci", -} - -// CollationNames maps MySQL default collation name to its ID -var CollationNames = map[string]uint8{ - "big5_chinese_ci": 1, - "latin2_czech_cs": 2, - "dec8_swedish_ci": 3, - "cp850_general_ci": 4, - "latin1_german1_ci": 5, - "hp8_english_ci": 6, - "koi8r_general_ci": 7, - "latin1_swedish_ci": 8, - "latin2_general_ci": 9, - "swe7_swedish_ci": 10, - "ascii_general_ci": 11, - "ujis_japanese_ci": 12, - "sjis_japanese_ci": 13, - "cp1251_bulgarian_ci": 14, - "latin1_danish_ci": 15, - "hebrew_general_ci": 16, - "tis620_thai_ci": 18, - "euckr_korean_ci": 19, - "latin7_estonian_cs": 20, - "latin2_hungarian_ci": 21, - "koi8u_general_ci": 22, - "cp1251_ukrainian_ci": 23, - "gb2312_chinese_ci": 24, - "greek_general_ci": 25, - "cp1250_general_ci": 26, - "latin2_croatian_ci": 27, - "gbk_chinese_ci": 28, - "cp1257_lithuanian_ci": 29, - "latin5_turkish_ci": 30, - "latin1_german2_ci": 31, - "armscii8_general_ci": 32, - "utf8_general_ci": 33, - "cp1250_czech_cs": 34, - "ucs2_general_ci": 35, - "cp866_general_ci": 36, - "keybcs2_general_ci": 37, - "macce_general_ci": 38, - "macroman_general_ci": 39, - "cp852_general_ci": 40, - "latin7_general_ci": 41, - "latin7_general_cs": 42, - "macce_bin": 43, - "cp1250_croatian_ci": 44, - "utf8mb4_general_ci": 45, - "utf8mb4_bin": 46, - "latin1_bin": 47, - "latin1_general_ci": 48, - "latin1_general_cs": 49, - "cp1251_bin": 50, - "cp1251_general_ci": 51, - "cp1251_general_cs": 52, - "macroman_bin": 53, - "utf16_general_ci": 54, - "utf16_bin": 55, - "utf16le_general_ci": 56, - "cp1256_general_ci": 57, - "cp1257_bin": 58, - "cp1257_general_ci": 59, - "utf32_general_ci": 60, - "utf32_bin": 61, - "utf16le_bin": 62, - "binary": 63, - "armscii8_bin": 64, - "ascii_bin": 65, - "cp1250_bin": 66, - "cp1256_bin": 67, - "cp866_bin": 68, - "dec8_bin": 69, - "greek_bin": 70, - "hebrew_bin": 71, - "hp8_bin": 72, - "keybcs2_bin": 73, - "koi8r_bin": 74, - "koi8u_bin": 75, - "latin2_bin": 77, - "latin5_bin": 78, - "latin7_bin": 79, - "cp850_bin": 80, - "cp852_bin": 81, - "swe7_bin": 82, - "utf8_bin": 83, - "big5_bin": 84, - "euckr_bin": 85, - "gb2312_bin": 86, - "gbk_bin": 87, - "sjis_bin": 88, - "tis620_bin": 89, - "ucs2_bin": 90, - "ujis_bin": 91, - "geostd8_general_ci": 92, - "geostd8_bin": 93, - "latin1_spanish_ci": 94, - "cp932_japanese_ci": 95, - "cp932_bin": 96, - "eucjpms_japanese_ci": 97, - "eucjpms_bin": 98, - "cp1250_polish_ci": 99, - "utf16_unicode_ci": 101, - "utf16_icelandic_ci": 102, - "utf16_latvian_ci": 103, - "utf16_romanian_ci": 104, - "utf16_slovenian_ci": 105, - "utf16_polish_ci": 106, - "utf16_estonian_ci": 107, - "utf16_spanish_ci": 108, - "utf16_swedish_ci": 109, - "utf16_turkish_ci": 110, - "utf16_czech_ci": 111, - "utf16_danish_ci": 112, - "utf16_lithuanian_ci": 113, - "utf16_slovak_ci": 114, - "utf16_spanish2_ci": 115, - "utf16_roman_ci": 116, - "utf16_persian_ci": 117, - "utf16_esperanto_ci": 118, - "utf16_hungarian_ci": 119, - "utf16_sinhala_ci": 120, - "utf16_german2_ci": 121, - "utf16_croatian_ci": 122, - "utf16_unicode_520_ci": 123, - "utf16_vietnamese_ci": 124, - "ucs2_unicode_ci": 128, - "ucs2_icelandic_ci": 129, - "ucs2_latvian_ci": 130, - "ucs2_romanian_ci": 131, - "ucs2_slovenian_ci": 132, - "ucs2_polish_ci": 133, - "ucs2_estonian_ci": 134, - "ucs2_spanish_ci": 135, - "ucs2_swedish_ci": 136, - "ucs2_turkish_ci": 137, - "ucs2_czech_ci": 138, - "ucs2_danish_ci": 139, - "ucs2_lithuanian_ci": 140, - "ucs2_slovak_ci": 141, - "ucs2_spanish2_ci": 142, - "ucs2_roman_ci": 143, - "ucs2_persian_ci": 144, - "ucs2_esperanto_ci": 145, - "ucs2_hungarian_ci": 146, - "ucs2_sinhala_ci": 147, - "ucs2_german2_ci": 148, - "ucs2_croatian_ci": 149, - "ucs2_unicode_520_ci": 150, - "ucs2_vietnamese_ci": 151, - "ucs2_general_mysql500_ci": 159, - "utf32_unicode_ci": 160, - "utf32_icelandic_ci": 161, - "utf32_latvian_ci": 162, - "utf32_romanian_ci": 163, - "utf32_slovenian_ci": 164, - "utf32_polish_ci": 165, - "utf32_estonian_ci": 166, - "utf32_spanish_ci": 167, - "utf32_swedish_ci": 168, - "utf32_turkish_ci": 169, - "utf32_czech_ci": 170, - "utf32_danish_ci": 171, - "utf32_lithuanian_ci": 172, - "utf32_slovak_ci": 173, - "utf32_spanish2_ci": 174, - "utf32_roman_ci": 175, - "utf32_persian_ci": 176, - "utf32_esperanto_ci": 177, - "utf32_hungarian_ci": 178, - "utf32_sinhala_ci": 179, - "utf32_german2_ci": 180, - "utf32_croatian_ci": 181, - "utf32_unicode_520_ci": 182, - "utf32_vietnamese_ci": 183, - "utf8_unicode_ci": 192, - "utf8_icelandic_ci": 193, - "utf8_latvian_ci": 194, - "utf8_romanian_ci": 195, - "utf8_slovenian_ci": 196, - "utf8_polish_ci": 197, - "utf8_estonian_ci": 198, - "utf8_spanish_ci": 199, - "utf8_swedish_ci": 200, - "utf8_turkish_ci": 201, - "utf8_czech_ci": 202, - "utf8_danish_ci": 203, - "utf8_lithuanian_ci": 204, - "utf8_slovak_ci": 205, - "utf8_spanish2_ci": 206, - "utf8_roman_ci": 207, - "utf8_persian_ci": 208, - "utf8_esperanto_ci": 209, - "utf8_hungarian_ci": 210, - "utf8_sinhala_ci": 211, - "utf8_german2_ci": 212, - "utf8_croatian_ci": 213, - "utf8_unicode_520_ci": 214, - "utf8_vietnamese_ci": 215, - "utf8_general_mysql500_ci": 223, - "utf8mb4_unicode_ci": 224, - "utf8mb4_icelandic_ci": 225, - "utf8mb4_latvian_ci": 226, - "utf8mb4_romanian_ci": 227, - "utf8mb4_slovenian_ci": 228, - "utf8mb4_polish_ci": 229, - "utf8mb4_estonian_ci": 230, - "utf8mb4_spanish_ci": 231, - "utf8mb4_swedish_ci": 232, - "utf8mb4_turkish_ci": 233, - "utf8mb4_czech_ci": 234, - "utf8mb4_danish_ci": 235, - "utf8mb4_lithuanian_ci": 236, - "utf8mb4_slovak_ci": 237, - "utf8mb4_spanish2_ci": 238, - "utf8mb4_roman_ci": 239, - "utf8mb4_persian_ci": 240, - "utf8mb4_esperanto_ci": 241, - "utf8mb4_hungarian_ci": 242, - "utf8mb4_sinhala_ci": 243, - "utf8mb4_german2_ci": 244, - "utf8mb4_croatian_ci": 245, - "utf8mb4_unicode_520_ci": 246, - "utf8mb4_vietnamese_ci": 247, -} - -// MySQL collation information. -const ( - UTF8Charset = "utf8" - UTF8MB4Charset = "utf8mb4" - DefaultCharset = UTF8MB4Charset - // DefaultCollationID is utf8mb4_bin(46) - DefaultCollationID = 46 - BinaryCollationID = 63 - UTF8DefaultCollation = "utf8_bin" - UTF8MB4DefaultCollation = "utf8mb4_bin" - DefaultCollationName = UTF8MB4DefaultCollation - - // MaxBytesOfCharacter, is the max bytes length of a character, - // refer to RFC3629, in UTF-8, characters from the U+0000..U+10FFFF range - // (the UTF-16 accessible range) are encoded using sequences of 1 to 4 octets. - MaxBytesOfCharacter = 4 -) - -// IsUTF8Charset checks if charset is utf8 or utf8mb4 -func IsUTF8Charset(charset string) bool { - return charset == UTF8Charset || charset == UTF8MB4Charset -} - -// RangeGraph defines valid unicode characters to use in column names. It strictly follows MySQL's definition. -// See #3994. -var RangeGraph = []*unicode.RangeTable{ - // _MY_PNT - unicode.No, - unicode.Mn, - unicode.Me, - unicode.Pc, - unicode.Pd, - unicode.Pd, - unicode.Ps, - unicode.Pe, - unicode.Pi, - unicode.Pf, - unicode.Po, - unicode.Sm, - unicode.Sc, - unicode.Sk, - unicode.So, - // _MY_U - unicode.Lu, - unicode.Lt, - unicode.Nl, - // _MY_L - unicode.Ll, - unicode.Lm, - unicode.Lo, - unicode.Nl, - unicode.Mn, - unicode.Mc, - unicode.Me, - // _MY_NMR - unicode.Nd, - unicode.Nl, - unicode.No, -} From e54162ebfe0ad673022acf83a26978dce0e4e217 Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 5 Nov 2018 17:26:00 +0800 Subject: [PATCH 06/11] fix ci --- planner/core/planbuilder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 215f9c456e9d1..88c746a528821 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -20,6 +20,7 @@ import ( "github.com/cznic/mathutil" "github.com/pingcap/errors" "github.com/pingcap/parser/ast" + "github.com/pingcap/parser/charset" "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/opcode" @@ -31,7 +32,6 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/parser_driver" - "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/ranger" ) From fdbc6e4b2c452b3bd6338e7cfc691ce5d9e7e27a Mon Sep 17 00:00:00 2001 From: winkyao Date: Thu, 8 Nov 2018 19:35:29 +0800 Subject: [PATCH 07/11] update go module --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b9bc33169b9c9..8732efff86006 100644 --- a/go.mod +++ b/go.mod @@ -69,7 +69,7 @@ require ( github.com/pingcap/errors v0.11.0 github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20181028030329-855d2192cdc7 - github.com/pingcap/parser v0.0.0-20181102070703-4acd198f5092 + github.com/pingcap/parser v0.0.0-20181108112017-a63108d7da4c github.com/pingcap/pd v2.1.0-rc.4+incompatible github.com/pingcap/tidb-tools v0.0.0-20181101090416-cfac1096162e github.com/pingcap/tipb v0.0.0-20181012112600-11e33c750323 diff --git a/go.sum b/go.sum index 7e6637029312b..f8824e633bd17 100644 --- a/go.sum +++ b/go.sum @@ -193,6 +193,8 @@ github.com/pingcap/parser v0.0.0-20181024082006-53ac409ed043 h1:P9Osi8lei5j2fiRg github.com/pingcap/parser v0.0.0-20181024082006-53ac409ed043/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/parser v0.0.0-20181102070703-4acd198f5092 h1:vGjjf7fhuaO9udn6QEFzvsNJDwVxFmdJvIJhCdCNe/E= github.com/pingcap/parser v0.0.0-20181102070703-4acd198f5092/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20181108112017-a63108d7da4c h1:qXcJU4FwcXUV4zN8Cg2Lht4LkJDFK+Tn9dGDJn6nAsw= +github.com/pingcap/parser v0.0.0-20181108112017-a63108d7da4c/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v0.0.0-20180619050643-0ec6ffcf94e8/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E= github.com/pingcap/pd v0.0.0-20181015053559-eb892dda1e33 h1:UQKEV9u9PR1RjFiJqqGijsHAEzTDZe89xdgB4Lj9S8Y= github.com/pingcap/pd v0.0.0-20181015053559-eb892dda1e33/go.mod h1:+bFEXnol47I8RhLpb0RbP5ZvpG6Ca7dw0LL/ARsmRk0= From 68ec4628641fbdf85215fb265cb4664e903c93df Mon Sep 17 00:00:00 2001 From: winkyao Date: Thu, 8 Nov 2018 19:52:56 +0800 Subject: [PATCH 08/11] fix ci --- expression/builtin_miscellaneous.go | 1 - go.mod | 2 +- store/mockstore/mocktikv/analyze.go | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/expression/builtin_miscellaneous.go b/expression/builtin_miscellaneous.go index eaad5108a1337..46239c7802f95 100644 --- a/expression/builtin_miscellaneous.go +++ b/expression/builtin_miscellaneous.go @@ -22,7 +22,6 @@ import ( "time" "github.com/pingcap/errors" - "github.com/pingcap/parser/charset" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" diff --git a/go.mod b/go.mod index 8ce29d723c96e..9928c48f12789 100644 --- a/go.mod +++ b/go.mod @@ -69,7 +69,7 @@ require ( github.com/pingcap/errors v0.11.0 github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20181105061835-1b5d69cd1d26 - github.com/pingcap/parser v0.0.0-20181102070703-4acd198f5092 + github.com/pingcap/parser v0.0.0-20181108112017-a63108d7da4c github.com/pingcap/pd v2.1.0-rc.4+incompatible github.com/pingcap/tidb-tools v0.0.0-20181101090416-cfac1096162e github.com/pingcap/tipb v0.0.0-20181012112600-11e33c750323 diff --git a/store/mockstore/mocktikv/analyze.go b/store/mockstore/mocktikv/analyze.go index fe36a4cbb13ce..5895fa3e56c68 100644 --- a/store/mockstore/mocktikv/analyze.go +++ b/store/mockstore/mocktikv/analyze.go @@ -18,7 +18,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/parser/ast" - "github.com/pingcap/parser/charset" "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/kv" From c0995b7cbb616f3c0c17e44346180c10f061c1b4 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 9 Nov 2018 11:15:34 +0800 Subject: [PATCH 09/11] address comments --- expression/aggregation/descriptor.go | 4 ++-- expression/builtin.go | 4 ++-- expression/builtin_cast.go | 6 +++--- server/server.go | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/expression/aggregation/descriptor.go b/expression/aggregation/descriptor.go index ccc9080d289ed..f4648fffab533 100644 --- a/expression/aggregation/descriptor.go +++ b/expression/aggregation/descriptor.go @@ -334,8 +334,8 @@ func (a *AggFuncDesc) typeInfer4Avg(ctx sessionctx.Context) { func (a *AggFuncDesc) typeInfer4GroupConcat(ctx sessionctx.Context) { a.RetTp = types.NewFieldType(mysql.TypeVarString) - a.RetTp.Charset = charset.CharsetUTF8MB4 - a.RetTp.Collate = charset.CollationUTF8MB4 + a.RetTp.Charset, a.RetTp.Collate = charset.GetDefaultCharsetAndCollate() + a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxBlobWidth, 0 // TODO: a.Args[i] = expression.WrapWithCastAsString(ctx, a.Args[i]) } diff --git a/expression/builtin.go b/expression/builtin.go index d5c720b91ed15..cb7549f41b587 100644 --- a/expression/builtin.go +++ b/expression/builtin.go @@ -149,7 +149,7 @@ func newBaseBuiltinFuncWithTp(ctx sessionctx.Context, args []Expression, retType if mysql.HasBinaryFlag(fieldType.Flag) && fieldType.Tp != mysql.TypeJSON { fieldType.Charset, fieldType.Collate = charset.CharsetBin, charset.CollationBin } else { - fieldType.Charset, fieldType.Collate = mysql.DefaultCharset, mysql.DefaultCollationName + fieldType.Charset, fieldType.Collate = charset.GetDefaultCharsetAndCollate() } return baseBuiltinFunc{ args: args, @@ -199,7 +199,7 @@ func (b *baseBuiltinFunc) getRetTp() *types.FieldType { b.tp.Tp = mysql.TypeMediumBlob } if len(b.tp.Charset) <= 0 { - b.tp.Charset, b.tp.Collate = mysql.DefaultCharset, mysql.DefaultCollationName + b.tp.Charset, b.tp.Collate = charset.GetDefaultCharsetAndCollate() } } return b.tp diff --git a/expression/builtin_cast.go b/expression/builtin_cast.go index 2f73b1e17d5f3..7b2b993952459 100644 --- a/expression/builtin_cast.go +++ b/expression/builtin_cast.go @@ -1741,7 +1741,7 @@ func WrapWithCastAsString(ctx sessionctx.Context, expr Expression) Expression { argLen = mysql.MaxIntWidth } tp := types.NewFieldType(mysql.TypeVarString) - tp.Charset, tp.Collate = charset.CharsetUTF8MB4, charset.CollationUTF8MB4 + tp.Charset, tp.Collate = charset.GetDefaultCharsetAndCollate() tp.Flen, tp.Decimal = argLen, types.UnspecifiedLength return BuildCastFunction(ctx, expr, tp) } @@ -1804,8 +1804,8 @@ func WrapWithCastAsJSON(ctx sessionctx.Context, expr Expression) Expression { Tp: mysql.TypeJSON, Flen: 12582912, // FIXME: Here the Flen is not trusted. Decimal: 0, - Charset: charset.CharsetUTF8MB4, - Collate: charset.CollationUTF8MB4, + Charset: mysql.DefaultCharset, + Collate: mysql.DefaultCollationName, Flag: mysql.BinaryFlag, } return BuildCastFunction(ctx, expr, tp) diff --git a/server/server.go b/server/server.go index 8854f9cb12050..010994bd44db8 100644 --- a/server/server.go +++ b/server/server.go @@ -153,6 +153,7 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) { var err error if cfg.Socket != "" { if s.listener, err = net.Listen("unix", cfg.Socket); err == nil { + // job.SnapshotVer == 0 means log.Infof("Server is running MySQL Protocol through Socket [%s]", cfg.Socket) } } else { From 5c1678dca1b7ddb50c54fa2b5b63b38482d3dcf6 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 9 Nov 2018 11:45:15 +0800 Subject: [PATCH 10/11] address comment --- executor/show.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show.go b/executor/show.go index b7b4da5dee126..e0679d0b82197 100644 --- a/executor/show.go +++ b/executor/show.go @@ -618,7 +618,7 @@ func (e *ShowExec) fetchShowCreateTable() error { buf.WriteString(") ENGINE=InnoDB") charsetName := tb.Meta().Charset if len(charsetName) == 0 { - charsetName = charset.CharsetUTF8MB4 + charsetName = mysql.DefaultCharset } collate := tb.Meta().Collate // Set default collate if collate is not specified. From 90b3a60e5658bbea5ff54b42a6fc8713442c7261 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 9 Nov 2018 14:00:14 +0800 Subject: [PATCH 11/11] cleanup --- server/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/server.go b/server/server.go index 010994bd44db8..8854f9cb12050 100644 --- a/server/server.go +++ b/server/server.go @@ -153,7 +153,6 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) { var err error if cfg.Socket != "" { if s.listener, err = net.Listen("unix", cfg.Socket); err == nil { - // job.SnapshotVer == 0 means log.Infof("Server is running MySQL Protocol through Socket [%s]", cfg.Socket) } } else {