Skip to content

Commit

Permalink
infoschema: Add partitions table
Browse files Browse the repository at this point in the history
To prevent mysqldump error:

1. Add File_Type column in files.

2. Add partitions table.
  • Loading branch information
shenli committed Apr 7, 2016
1 parent cfc2698 commit faa70cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ var (
filesTbl table.Table
defTbl table.Table
profilingTbl table.Table
partitionsTbl table.Table
nameToTable map[string]table.Table

perfHandle perfschema.PerfSchema
Expand Down
9 changes: 9 additions & 0 deletions infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ func (*testSuite) TestT(c *C) {
idx, ok := is.IndexByName(dbName, tbName, idxName)
c.Assert(ok, IsTrue)
c.Assert(idx, NotNil)

// Make sure partitions table exists
tb, err = is.TableByName(model.NewCIStr("information_schema"), model.NewCIStr("partitions"))
c.Assert(err, IsNil)
c.Assert(tb, NotNil)

col, ok = is.ColumnByName(model.NewCIStr("information_schema"), model.NewCIStr("files"), model.NewCIStr("FILE_TYPE"))
c.Assert(ok, IsTrue)
c.Assert(col, NotNil)
}

func genGlobalID(store kv.Storage) (int64, error) {
Expand Down
32 changes: 32 additions & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
tableFiles = "FILES"
catalogVal = "def"
tableProfiling = "PROFILING"
tablePartitions = "PARTITIONS"
)

type columnInfo struct {
Expand Down Expand Up @@ -197,6 +198,35 @@ var collationsCols = []columnInfo{
{"SORTLEN", mysql.TypeLonglong, 3, 0, nil, nil},
}

// See: https://dev.mysql.com/doc/refman/5.7/en/partitions-table.html
var partitionsCols = []columnInfo{
{"TABLE_CATALOG", mysql.TypeVarchar, 512, 0, nil, nil},
{"TABLE_SCHEMA", mysql.TypeVarchar, 64, 0, nil, nil},
{"TABLE_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"PARTITION_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"SUBPARTITION_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"PARTITION_ORDINAL_POSITION", mysql.TypeLonglong, 21, 0, nil, nil},
{"SUBPARTITION_ORDINAL_POSITION", mysql.TypeLonglong, 21, 0, nil, nil},
{"PARTITION_METHOD", mysql.TypeVarchar, 18, 0, nil, nil},
{"SUBPARTITION_METHOD", mysql.TypeVarchar, 12, 0, nil, nil},
{"PARTITION_EXPRESSION", mysql.TypeLongBlob, types.UnspecifiedLength, 0, nil, nil},
{"SUBPARTITION_EXPRESSION", mysql.TypeLongBlob, types.UnspecifiedLength, 0, nil, nil},
{"PARTITION_DESCRIPTION", mysql.TypeLongBlob, types.UnspecifiedLength, 0, nil, nil},
{"TABLE_ROWS", mysql.TypeLonglong, 21, 0, nil, nil},
{"AVG_ROW_LENGTH", mysql.TypeLonglong, 21, 0, nil, nil},
{"DATA_LENGTH", mysql.TypeLonglong, 21, 0, nil, nil},
{"MAX_DATA_LENGTH", mysql.TypeLonglong, 21, 0, nil, nil},
{"INDEX_LENGTH", mysql.TypeLonglong, 21, 0, nil, nil},
{"DATA_FREE", mysql.TypeLonglong, 21, 0, nil, nil},
{"CREATE_TIME", mysql.TypeDatetime, 0, 0, nil, nil},
{"UPDATE_TIME", mysql.TypeDatetime, 0, 0, nil, nil},
{"CHECK_TIME", mysql.TypeDatetime, 0, 0, nil, nil},
{"CHECKSUM", mysql.TypeLonglong, 21, 0, nil, nil},
{"PARTITION_COMMENT", mysql.TypeVarchar, 80, 0, nil, nil},
{"NODEGROUP", mysql.TypeVarchar, 12, 0, nil, nil},
{"TABLESPACE_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
}

func dataForCharacterSets() (records [][]types.Datum) {
records = append(records,
types.MakeDatums("ascii", "ascii_general_ci", "US ASCII", 1),
Expand All @@ -222,6 +252,7 @@ func dataForColltions() (records [][]types.Datum) {
var filesCols = []columnInfo{
{"FILE_ID", mysql.TypeLonglong, 4, 0, nil, nil},
{"FILE_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"FILE_TYPE", mysql.TypeVarchar, 20, 0, nil, nil},
{"TABLESPACE_NAME", mysql.TypeVarchar, 20, 0, nil, nil},
{"TABLE_CATALOG", mysql.TypeVarchar, 64, 0, nil, nil},
{"TABLE_SCHEMA", mysql.TypeVarchar, 64, 0, nil, nil},
Expand Down Expand Up @@ -450,6 +481,7 @@ var tableNameToColumns = map[string]([]columnInfo){
tableCollations: collationsCols,
tableFiles: filesCols,
tableProfiling: profilingCols,
tablePartitions: partitionsCols,
}

func createMemoryTable(meta *model.TableInfo, alloc autoid.Allocator) (table.Table, error) {
Expand Down

0 comments on commit faa70cf

Please sign in to comment.