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

show column comment, table auto-increment; change index default collation #4303

Merged
merged 5 commits into from
Aug 26, 2017
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
6 changes: 4 additions & 2 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ func (e *ShowExec) fetchShowColumns() error {
return nil
}

// TODO: index collation can have values A (ascending) or NULL (not sorted).
// see: https://dev.mysql.com/doc/refman/5.7/en/show-index.html
func (e *ShowExec) fetchShowIndex() error {
tb, err := e.getTable()
if err != nil {
Expand All @@ -285,7 +287,7 @@ func (e *ShowExec) fetchShowIndex() error {
"PRIMARY", // Key_name
1, // Seq_in_index
pkCol.Name.O, // Column_name
"utf8_bin", // Colation
"A", // Collation
0, // Cardinality
nil, // Sub_part
nil, // Packed
Expand All @@ -312,7 +314,7 @@ func (e *ShowExec) fetchShowIndex() error {
idx.Meta().Name.O, // Key_name
i+1, // Seq_in_index
col.Name.O, // Column_name
"utf8_bin", // Colation
"A", // Collation
0, // Cardinality
subPart, // Sub_part
nil, // Packed
Expand Down
37 changes: 28 additions & 9 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ func (s *testSuite) TestShow(c *C) {
tk.MustExec(`create index idx7 on show_index (id);`)
testSQL = "SHOW index from show_index;"
tk.MustQuery(testSQL).Check(testutil.RowsWithSep("|",
"show_index|0|PRIMARY|1|id|utf8_bin|0|<nil>|<nil>||BTREE||",
"show_index|1|cIdx|1|c|utf8_bin|0|<nil>|<nil>|YES|HASH||index_comment_for_cIdx",
"show_index|1|idx1|1|id|utf8_bin|0|<nil>|<nil>|YES|HASH||",
"show_index|1|idx2|1|id|utf8_bin|0|<nil>|<nil>|YES|BTREE||idx",
"show_index|1|idx3|1|id|utf8_bin|0|<nil>|<nil>|YES|HASH||idx",
"show_index|1|idx4|1|id|utf8_bin|0|<nil>|<nil>|YES|BTREE||idx",
"show_index|1|idx5|1|id|utf8_bin|0|<nil>|<nil>|YES|BTREE||idx",
"show_index|1|idx6|1|id|utf8_bin|0|<nil>|<nil>|YES|HASH||",
"show_index|1|idx7|1|id|utf8_bin|0|<nil>|<nil>|YES|BTREE||",
"show_index|0|PRIMARY|1|id|A|0|<nil>|<nil>||BTREE||",
"show_index|1|cIdx|1|c|A|0|<nil>|<nil>|YES|HASH||index_comment_for_cIdx",
"show_index|1|idx1|1|id|A|0|<nil>|<nil>|YES|HASH||",
"show_index|1|idx2|1|id|A|0|<nil>|<nil>|YES|BTREE||idx",
"show_index|1|idx3|1|id|A|0|<nil>|<nil>|YES|HASH||idx",
"show_index|1|idx4|1|id|A|0|<nil>|<nil>|YES|BTREE||idx",
"show_index|1|idx5|1|id|A|0|<nil>|<nil>|YES|BTREE||idx",
"show_index|1|idx6|1|id|A|0|<nil>|<nil>|YES|HASH||",
"show_index|1|idx7|1|id|A|0|<nil>|<nil>|YES|BTREE||",
))

// For show like with escape
Expand Down Expand Up @@ -129,6 +129,25 @@ func (s *testSuite) TestShow(c *C) {
tk.MustExec("use show_test_DB")
result = tk.MustQuery("SHOW index from show_index from test where Column_name = 'c'")
c.Check(result.Rows(), HasLen, 1)

// Test show full columns
// for issue https://github.com/pingcap/tidb/issues/4224
tk.MustExec(`drop table if exists show_test_comment`)
tk.MustExec(`create table show_test_comment (id int not null default 0 comment "show_test_comment_id")`)
tk.MustQuery(`show full columns from show_test_comment`).Check(testutil.RowsWithSep("|",
"id|int(11)|binary|NO||0||select,insert,update,references|show_test_comment_id",
))

// Test show create table with AUTO_INCREMENT option
// for issue https://github.com/pingcap/tidb/issues/3747
tk.MustExec(`drop table if exists show_auto_increment`)
tk.MustExec(`create table show_auto_increment (id int) auto_increment=4`)
tk.MustQuery(`show create table show_auto_increment`).Check(testutil.RowsWithSep("|",
""+
"show_auto_increment CREATE TABLE `show_auto_increment` (\n"+
" `id` int(11) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4",
))
}

func (s *testSuite) TestShowVisibility(c *C) {
Expand Down
44 changes: 22 additions & 22 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,27 +634,27 @@ func dataForTables(schemas []*model.DBInfo) [][]types.Datum {
for _, schema := range schemas {
for _, table := range schema.Tables {
record := types.MakeDatums(
catalogVal, // TABLE_CATALOG
schema.Name.O, // TABLE_SCHEMA
table.Name.O, // TABLE_NAME
"BASE TABLE", // TABLE_TYPE
"InnoDB", // ENGINE
uint64(10), // VERSION
"Compact", // ROW_FORMAT
uint64(0), // TABLE_ROWS
uint64(0), // AVG_ROW_LENGTH
uint64(16384), // DATA_LENGTH
uint64(0), // MAX_DATA_LENGTH
uint64(0), // INDEX_LENGTH
uint64(0), // DATA_FREE
nil, // AUTO_INCREMENT
nil, // CREATE_TIME
nil, // UPDATE_TIME
nil, // CHECK_TIME
"latin1_swedish_ci", // TABLE_COLLATION
nil, // CHECKSUM
"", // CREATE_OPTIONS
"", // TABLE_COMMENT
catalogVal, // TABLE_CATALOG
schema.Name.O, // TABLE_SCHEMA
table.Name.O, // TABLE_NAME
"BASE TABLE", // TABLE_TYPE
"InnoDB", // ENGINE
uint64(10), // VERSION
"Compact", // ROW_FORMAT
uint64(0), // TABLE_ROWS
uint64(0), // AVG_ROW_LENGTH
uint64(16384), // DATA_LENGTH
uint64(0), // MAX_DATA_LENGTH
uint64(0), // INDEX_LENGTH
uint64(0), // DATA_FREE
table.AutoIncID, // AUTO_INCREMENT
nil, // CREATE_TIME
nil, // UPDATE_TIME
nil, // CHECK_TIME
table.Collate, // TABLE_COLLATION
nil, // CHECKSUM
"", // CREATE_OPTIONS
table.Comment, // TABLE_COMMENT
)
rows = append(rows, record)
}
Expand Down Expand Up @@ -712,7 +712,7 @@ func dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) [][]types
columnDesc.Key, // COLUMN_KEY
columnDesc.Extra, // EXTRA
"select,insert,update,references", // PRIVILEGES
"", // COLUMN_COMMENT
columnDesc.Comment, // COLUMN_COMMENT
)
rows = append(rows, record)
}
Expand Down
2 changes: 1 addition & 1 deletion table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func NewColDesc(col *Column) *ColDesc {
DefaultValue: defaultValue,
Extra: extra,
Privileges: defaultPrivileges,
Comment: "",
Comment: col.Comment,
}
}

Expand Down