diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 7e455013439e9..6ac34701538f2 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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 diff --git a/executor/show.go b/executor/show.go index 8823d17d3d3f8..156dc486d9d04 100644 --- a/executor/show.go +++ b/executor/show.go @@ -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 { diff --git a/executor/show_test.go b/executor/show_test.go index b7ae53e324c51..80a71938847da 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -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));`) diff --git a/model/model.go b/model/model.go index 17dc813c7c78d..c488ac86a4791 100644 --- a/model/model.go +++ b/model/model.go @@ -169,6 +169,8 @@ type TableInfo struct { ShardRowIDBits uint64 Partition *PartitionInfo `json:"partition"` + + Compression string `json:"compression"` } // GetPartitionInfo returns the partition information. diff --git a/parser/parser_test.go b/parser/parser_test.go index ac33937635704..eb36ab0ab2884 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -1450,6 +1450,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}, @@ -1700,6 +1703,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},