Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "executor/show: show create table return utf8mb4 charset. (#8604) #8782

Merged
merged 4 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,6 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e
if err != nil {
return errors.Trace(err)
}
if len(tbInfo.Charset) != 0 && strings.ToLower(tbInfo.Charset) != mysql.DefaultCharset {
ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf(`TiDB only supports the "utf8mb4" character set, so "%s" does not take effect.`, tbInfo.Charset))
}

err = d.doDDLJob(ctx, job)
if err == nil {
if tbInfo.AutoIncID > 1 {
Expand Down
2 changes: 1 addition & 1 deletion executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (s *seqTestSuite) TestShow(c *C) {
row := result.Rows()[0]
// For issue https://github.com/pingcap/tidb/issues/1061
expectedRow := []interface{}{
"SHOW_test", "CREATE TABLE `SHOW_test` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `c1` int(11) DEFAULT NULL COMMENT 'c1_comment',\n `c2` int(11) DEFAULT NULL,\n `c3` int(11) DEFAULT '1',\n `c4` text DEFAULT NULL,\n `c5` tinyint(1) DEFAULT NULL,\n PRIMARY KEY (`id`),\n KEY `idx_wide_c4` (`c3`,`c4`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=28934 COMMENT='table_comment'"}
"SHOW_test", "CREATE TABLE `SHOW_test` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `c1` int(11) DEFAULT NULL COMMENT 'c1_comment',\n `c2` int(11) DEFAULT NULL,\n `c3` int(11) DEFAULT '1',\n `c4` text DEFAULT NULL,\n `c5` tinyint(1) DEFAULT NULL,\n PRIMARY KEY (`id`),\n KEY `idx_wide_c4` (`c3`,`c4`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=28934 COMMENT='table_comment'"}
for i, r := range row {
c.Check(r, Equals, expectedRow[i])
}
Expand Down
22 changes: 18 additions & 4 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,24 @@ func (e *ShowExec) fetchShowCreateTable() error {
buf.WriteString("\n")

buf.WriteString(") ENGINE=InnoDB")
// Currently TiDB treat all the data as utf8mb4 actually.
// Make the TiDB's query result consistent with its actual behavior.
charsetName, collate := charset.GetDefaultCharsetAndCollate()
fmt.Fprintf(&buf, " DEFAULT CHARSET=%s COLLATE=%s", charsetName, collate)
charsetName := tb.Meta().Charset
if len(charsetName) == 0 {
charsetName = mysql.DefaultCharset
}
collate := tb.Meta().Collate
// Set default collate if collate is not specified.
if len(collate) == 0 {
collate = getDefaultCollate(charsetName)
}
// Because we only support case sensitive utf8_bin collate, we need to explicitly set the default charset and collation
// to make it work on MySQL server which has default collate utf8_general_ci.
if len(collate) == 0 {
// If we can not find default collate for the given charset,
// do not show the collate part.
fmt.Fprintf(&buf, " DEFAULT CHARSET=%s", charsetName)
} else {
fmt.Fprintf(&buf, " DEFAULT CHARSET=%s COLLATE=%s", charsetName, collate)
}

// Displayed if the compression typed is set.
if len(tb.Meta().Compression) != 0 {
Expand Down
18 changes: 0 additions & 18 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,3 @@ func (s *testSuite2) TestShowEscape(c *C) {
tk.MustExec("rename table \"t`abl\"\"e\" to t")
tk.MustExec("set sql_mode=@old_sql_mode")
}

func (s *testSuite) TestShowCreateTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1,t2,t3")
tk.MustExec("create table t1 (a varchar(10));")
r := tk.MustQuery("show warnings")
c.Assert(len(r.Rows()), Equals, 0)
tk.MustExec("create table t2 (a varchar(10)) charset=UTF8mb4;")
r = tk.MustQuery("show warnings")
c.Assert(len(r.Rows()), Equals, 0)
tk.MustExec("create table t3 (a varchar(10)) charset=utf8;")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", `Warning|1105|TiDB only supports the "utf8mb4" character set, so "utf8" does not take effect.`))
tk.MustQuery("show create table t1;").Check(testutil.RowsWithSep("|", "t1|CREATE TABLE `t1` (\n `a` varchar(10) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustQuery("show create table t2;").Check(testutil.RowsWithSep("|", "t2|CREATE TABLE `t2` (\n `a` varchar(10) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustQuery("show create table t3;").Check(testutil.RowsWithSep("|", "t3|CREATE TABLE `t3` (\n `a` varchar(10) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustExec("drop table t1,t2,t3")
}