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

executor: support table partition in show create table stmt #6292

Merged
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
18 changes: 18 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,24 @@ func (e *ShowExec) fetchShowCreateTable() error {
buf.WriteString(fmt.Sprintf(" DEFAULT CHARSET=%s COLLATE=%s", charsetName, collate))
}

// add partition info here.
partitionInfo := tb.Meta().Partition
if partitionInfo != nil {
buf.WriteString(fmt.Sprintf("\nPARTITION BY %s ( %s ) (\n", partitionInfo.Type.String(), partitionInfo.Expr))
for i, def := range partitionInfo.Definitions {
if i < len(partitionInfo.Definitions)-1 {
buf.WriteString(fmt.Sprintf(" PARTITION %s VALUES LESS THAN %s,\n", def.Name, def.LessThan[0]))
} else {
if def.MaxValue {
buf.WriteString(fmt.Sprintf(" PARTITION %s VALUES LESS THAN %s\n", def.Name, "MAXVALUE"))
} else {
buf.WriteString(fmt.Sprintf(" PARTITION %s VALUES LESS THAN %s\n", def.Name, def.LessThan[0]))
}
}
}
buf.WriteString(")")
}

if hasAutoIncID {
autoIncID, err := tb.Allocator(e.ctx).NextGlobalAutoID(tb.Meta().ID)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,17 @@ func (s *testSuite) TestShow(c *C) {
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))

// Test range partition
tk.MustExec(`drop table if exists t`)
tk.MustExec(`CREATE TABLE t (a int) PARTITION BY RANGE(a) (
PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN (MAXVALUE))`)
tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|",
"t CREATE TABLE `t` (\n"+
" `a` int(11) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"+"\nPARTITION BY RANGE ( `a` ) (\n PARTITION p0 VALUES LESS THAN 10,\n PARTITION p1 VALUES LESS THAN 20,\n PARTITION p2 VALUES LESS THAN MAXVALUE\n)",
))
}

func (s *testSuite) TestShowVisibility(c *C) {
Expand Down
14 changes: 14 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ const (
PartitionTypeList PartitionType = 3
)

func (p PartitionType) String() string {
switch p {
case PartitionTypeRange:
return "RANGE"
case PartitionTypeHash:
return "HASH"
case PartitionTypeList:
return "LIST"
default:
return ""
}

}

// PartitionInfo provides table partition info.
type PartitionInfo struct {
Type PartitionType
Expand Down