Skip to content

Commit

Permalink
executor: fix show create table with set and enum (#36327)
Browse files Browse the repository at this point in the history
close #36317
  • Loading branch information
Defined2014 authored Jul 19, 2022
1 parent a1abdbe commit a0cced2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/terror"
field_types "github.com/pingcap/tidb/parser/types"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/plugin"
"github.com/pingcap/tidb/privilege"
Expand Down Expand Up @@ -957,7 +958,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
buf.WriteString(",\n")
}
fmt.Fprintf(buf, " %s %s", stringutil.Escape(col.Name.O, sqlMode), col.GetTypeDesc())
if col.GetCharset() != "binary" {
if field_types.HasCharset(&col.FieldType) {
if col.GetCharset() != tblCharset {
fmt.Fprintf(buf, " CHARACTER SET %s", col.GetCharset())
}
Expand Down
11 changes: 11 additions & 0 deletions executor/showtest/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ func TestShowCreateTable(t *testing.T) {
" `b` varchar(20) DEFAULT '\\\\',\n"+
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(" +
"a set('a', 'b') charset binary," +
"b enum('a', 'b') charset ascii);")
tk.MustQuery("show create table t;").Check(testkit.RowsWithSep("|",
""+
"t CREATE TABLE `t` (\n"+
" `a` set('a','b') CHARACTER SET binary COLLATE binary DEFAULT NULL,\n"+
" `b` enum('a','b') CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func TestShowCreateTablePlacement(t *testing.T) {
Expand Down

0 comments on commit a0cced2

Please sign in to comment.