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

ddl:support 'show create table with compression' #7782

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,8 @@ func handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo) err
tbInfo.Charset = op.StrValue
case ast.TableOptionCollate:
tbInfo.Collate = op.StrValue
case ast.TableOptionCompression:
tbInfo.Compression = op.StrValue
case ast.TableOptionShardRowID:
if hasAutoIncrementColumn(tbInfo) && op.UintValue != 0 {
return errUnsupportedShardRowIDBits
Expand Down
5 changes: 5 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ func (e *ShowExec) fetchShowCreateTable() error {
buf.WriteString(fmt.Sprintf(" DEFAULT CHARSET=%s COLLATE=%s", charsetName, collate))
}

// Displayed if the compression typed is set.
if len(tb.Meta().Compression) != 0 {
buf.WriteString(fmt.Sprintf(" COMPRESSION=`%s`", tb.Meta().Compression))
}

// add partition info here.
partitionInfo := tb.Meta().Partition
if partitionInfo != nil {
Expand Down
9 changes: 9 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ func (s *testSuite) TestShow(c *C) {
") 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)",
))

// Test show create table compression type.
tk.MustExec(`drop table if exists t1`)
tk.MustExec(`CREATE TABLE t1 (c1 INT) COMPRESSION="zlib";`)
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`",
))

// Test show create table year type
tk.MustExec(`drop table if exists t`)
tk.MustExec(`create table t(y year unsigned signed zerofill zerofill, x int, primary key(y));`)
Expand Down
2 changes: 2 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ type TableInfo struct {
ShardRowIDBits uint64

Partition *PartitionInfo `json:"partition"`

Compression string `json:"compression"`
}

// GetPartitionInfo returns the partition information.
Expand Down
5 changes: 5 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,9 @@ func (s *testParserSuite) TestDDL(c *C) {
{"create table t (c int) PACK_KEYS = 1", true},
{"create table t (c int) PACK_KEYS = 0", true},
{"create table t (c int) PACK_KEYS = DEFAULT", true},
{`create table testTableCompression (c VARCHAR(15000)) compression="ZLIB";`, true},
{`create table t1 (c1 int) compression="zlib";`, true},

// partition option
{"create table t (c int) PARTITION BY HASH (c) PARTITIONS 32;", true},
{"create table t (c int) PARTITION BY RANGE (Year(VDate)) (PARTITION p1980 VALUES LESS THAN (1980) ENGINE = MyISAM, PARTITION p1990 VALUES LESS THAN (1990) ENGINE = MyISAM, PARTITION pothers VALUES LESS THAN MAXVALUE ENGINE = MyISAM)", true},
Expand Down Expand Up @@ -1696,6 +1699,8 @@ func (s *testParserSuite) TestDDL(c *C) {
{"ALTER TABLE t FORCE", true},
{"ALTER TABLE t DROP INDEX;", false},
{"ALTER TABLE t DROP COLUMN a CASCADE", true},
{`ALTER TABLE testTableCompression COMPRESSION="LZ4";`, true},
{`ALTER TABLE t1 COMPRESSION="zlib";`, true},

// For #6405
{"ALTER TABLE t RENAME KEY a TO b;", true},
Expand Down