Skip to content

Commit

Permalink
executor: fix show create table int default value (pingcap#20462)
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored Oct 28, 2020
1 parent bf043c2 commit a55a51a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ HashJoin_10 7984.01 root semi join, equal:[eq(test.t1.a, test.t2.a)], other con
drop table t;
CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,
i int(10) unsigned DEFAULT NULL,
x int(10) unsigned DEFAULT 0,
x int(10) unsigned DEFAULT '0',
PRIMARY KEY (`id`)
);
explain select row_number() over( partition by i ) - x as rnk from t;
Expand Down
2 changes: 1 addition & 1 deletion cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ explain select * from t1 where t1.a in (select t2.a as a from t2 where t2.b > t1
drop table t;
CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,
i int(10) unsigned DEFAULT NULL,
x int(10) unsigned DEFAULT 0,
x int(10) unsigned DEFAULT '0',
PRIMARY KEY (`id`)
);
explain select row_number() over( partition by i ) - x as rnk from t;
14 changes: 7 additions & 7 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ func (s *testIntegrationSuite1) TestIssue5092(c *C) {
tk.MustExec("alter table t_issue_5092 add column d int default 4 after c1, add column aa int default 0 first")
tk.MustQuery("select * from t_issue_5092").Check(testkit.Rows("0 1 2 22 3 33 4"))
tk.MustQuery("show create table t_issue_5092").Check(testkit.Rows("t_issue_5092 CREATE TABLE `t_issue_5092` (\n" +
" `aa` int(11) DEFAULT 0,\n" +
" `a` int(11) DEFAULT 1,\n" +
" `b` int(11) DEFAULT 2,\n" +
" `b1` int(11) DEFAULT 22,\n" +
" `c` int(11) DEFAULT 3,\n" +
" `c1` int(11) DEFAULT 33,\n" +
" `d` int(11) DEFAULT 4\n" +
" `aa` int(11) DEFAULT '0',\n" +
" `a` int(11) DEFAULT '1',\n" +
" `b` int(11) DEFAULT '2',\n" +
" `b1` int(11) DEFAULT '22',\n" +
" `c` int(11) DEFAULT '3',\n" +
" `c1` int(11) DEFAULT '33',\n" +
" `d` int(11) DEFAULT '4'\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustExec("drop table t_issue_5092")

Expand Down
6 changes: 3 additions & 3 deletions ddl/failtest/fail_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ func (s *testFailDBSuite) TestModifyColumn(c *C) {
tk.MustQuery("select * from t").Check(testkit.Rows("2 1 3", "22 11 33"))
tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `bb` mediumint(9) DEFAULT NULL,\n" +
" `a` int(11) NOT NULL DEFAULT 1,\n" +
" `c` int(11) NOT NULL DEFAULT 0,\n" +
" `a` int(11) NOT NULL DEFAULT '1',\n" +
" `c` int(11) NOT NULL DEFAULT '0',\n" +
" PRIMARY KEY (`c`),\n" +
" KEY `idx` (`bb`),\n" +
" KEY `idx1` (`a`),\n" +
Expand All @@ -495,7 +495,7 @@ func (s *testFailDBSuite) TestModifyColumn(c *C) {
tk.MustExec("alter table t change column a aa mediumint after c")
tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `bb` mediumint(9) DEFAULT NULL,\n" +
" `c` int(11) NOT NULL DEFAULT 0,\n" +
" `c` int(11) NOT NULL DEFAULT '0',\n" +
" `aa` mediumint(9) DEFAULT NULL,\n" +
" PRIMARY KEY (`c`),\n" +
" KEY `idx` (`bb`),\n" +
Expand Down
4 changes: 2 additions & 2 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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=utf8 COLLATE=utf8_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 All @@ -215,7 +215,7 @@ func (s *seqTestSuite) 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=utf8mb4 COLLATE=utf8mb4_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])
}
Expand Down
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
if col.Tp == mysql.TypeBit {
defaultValBinaryLiteral := types.BinaryLiteral(defaultValStr)
fmt.Fprintf(buf, " DEFAULT %s", defaultValBinaryLiteral.ToBitLiteralString(true))
} else if types.IsTypeNumeric(col.Tp) || col.DefaultIsExpr {
} else if col.DefaultIsExpr {
fmt.Fprintf(buf, " DEFAULT %s", format.OutputFormat(defaultValStr))
} else {
fmt.Fprintf(buf, " DEFAULT '%s'", format.OutputFormat(defaultValStr))
Expand Down
13 changes: 12 additions & 1 deletion executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,17 @@ func (s *testSuite5) TestShowCreateTable(c *C) {
))
tk.MustExec("drop table t")

// for issue #20446
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1(c int unsigned default 0);")
tk.MustQuery("show create table `t1`").Check(testutil.RowsWithSep("|",
""+
"t1 CREATE TABLE `t1` (\n"+
" `c` int(10) unsigned DEFAULT '0'\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
tk.MustExec("drop table t1")

tk.MustExec("CREATE TABLE `log` (" +
"`LOG_ID` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT," +
"`ROUND_ID` bigint(20) UNSIGNED NOT NULL," +
Expand Down Expand Up @@ -745,7 +756,7 @@ func (s *testSuite5) TestShowCreateTable(c *C) {
tk.MustQuery("show create table default_num").Check(testutil.RowsWithSep("|",
""+
"default_num CREATE TABLE `default_num` (\n"+
" `a` int(11) DEFAULT 11\n"+
" `a` int(11) DEFAULT '11'\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
tk.MustExec(`drop table if exists default_varchar`)
Expand Down
4 changes: 2 additions & 2 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ func (s *testTableSuite) TestInfoschemaFieldValue(c *C) {
tk.MustQuery("show create table information_schema.PROCESSLIST").Check(
testkit.Rows("" +
"PROCESSLIST CREATE TABLE `PROCESSLIST` (\n" +
" `ID` bigint(21) unsigned NOT NULL DEFAULT 0,\n" +
" `ID` bigint(21) unsigned NOT NULL DEFAULT '0',\n" +
" `USER` varchar(16) NOT NULL DEFAULT '',\n" +
" `HOST` varchar(64) NOT NULL DEFAULT '',\n" +
" `DB` varchar(64) DEFAULT NULL,\n" +
" `COMMAND` varchar(16) NOT NULL DEFAULT '',\n" +
" `TIME` int(7) NOT NULL DEFAULT 0,\n" +
" `TIME` int(7) NOT NULL DEFAULT '0',\n" +
" `STATE` varchar(7) DEFAULT NULL,\n" +
" `INFO` longtext DEFAULT NULL,\n" +
" `DIGEST` varchar(64) DEFAULT '',\n" +
Expand Down

0 comments on commit a55a51a

Please sign in to comment.