Skip to content

Commit

Permalink
infoschema: add more empty tables (pingcap#3127)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and coocood committed Apr 24, 2017
1 parent 93f4780 commit 73c9e12
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 40 deletions.
2 changes: 1 addition & 1 deletion executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (s *testSuite) TestAggregation(c *C) {

result = tk.MustQuery("select count(*) from information_schema.columns")
// When adding new memory table in information_schema, please update this variable.
columnCountOfAllInformationSchemaTables := "628"
columnCountOfAllInformationSchemaTables := "714"
result.Check(testkit.Rows(columnCountOfAllInformationSchemaTables))

tk.MustExec("drop table if exists t1")
Expand Down
11 changes: 11 additions & 0 deletions infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ func (*testSuite) TestInfoTables(c *C) {
"ENGINES",
"VIEWS",
"ROUTINES",
"SCHEMA_PRIVILEGES",
"COLUMN_PRIVILEGES",
"TABLE_PRIVILEGES",
"PARAMETERS",
"EVENTS",
"GLOBAL_STATUS",
"GLOBAL_VARIABLES",
"SESSION_STATUS",
"OPTIMIZER_TRACE",
"TABLESPACES",
"COLLATION_CHARACTER_SET_APPLICABILITY",
}
for _, t := range info_tables {
tb, err1 := is.TableByName(model.NewCIStr(infoschema.Name), model.NewCIStr(t))
Expand Down
231 changes: 192 additions & 39 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,37 @@ import (
)

const (
tableSchemata = "SCHEMATA"
tableTables = "TABLES"
tableColumns = "COLUMNS"
tableStatistics = "STATISTICS"
tableCharacterSets = "CHARACTER_SETS"
tableCollations = "COLLATIONS"
tableFiles = "FILES"
catalogVal = "def"
tableProfiling = "PROFILING"
tablePartitions = "PARTITIONS"
tableKeyColumm = "KEY_COLUMN_USAGE"
tableReferConst = "REFERENTIAL_CONSTRAINTS"
tableSessionVar = "SESSION_VARIABLES"
tablePlugins = "PLUGINS"
tableConstraints = "TABLE_CONSTRAINTS"
tableTriggers = "TRIGGERS"
tableUserPrivileges = "USER_PRIVILEGES"
tableEngines = "ENGINES"
tableViews = "VIEWS"
tableRoutines = "ROUTINES"
tableSchemata = "SCHEMATA"
tableTables = "TABLES"
tableColumns = "COLUMNS"
tableStatistics = "STATISTICS"
tableCharacterSets = "CHARACTER_SETS"
tableCollations = "COLLATIONS"
tableFiles = "FILES"
catalogVal = "def"
tableProfiling = "PROFILING"
tablePartitions = "PARTITIONS"
tableKeyColumm = "KEY_COLUMN_USAGE"
tableReferConst = "REFERENTIAL_CONSTRAINTS"
tableSessionVar = "SESSION_VARIABLES"
tablePlugins = "PLUGINS"
tableConstraints = "TABLE_CONSTRAINTS"
tableTriggers = "TRIGGERS"
tableUserPrivileges = "USER_PRIVILEGES"
tableSchemaPrivileges = "SCHEMA_PRIVILEGES"
tableTablePrivileges = "TABLE_PRIVILEGES"
tableColumnPrivileges = "COLUMN_PRIVILEGES"
tableEngines = "ENGINES"
tableViews = "VIEWS"
tableRoutines = "ROUTINES"
tableParameters = "PARAMETERS"
tableEvents = "EVENTS"
tableGlobalStatus = "GLOBAL_STATUS"
tableGlobalVariables = "GLOBAL_VARIABLES"
tableSessionStatus = "SESSION_STATUS"
tableOptimizerTrace = "OPTIMIZER_TRACE"
tableTableSpaces = "TABLESPACES"
tableCollationCharacterSetApplicability = "COLLATION_CHARACTER_SET_APPLICABILITY"
)

type columnInfo struct {
Expand Down Expand Up @@ -334,6 +345,33 @@ var tableUserPrivilegesCols = []columnInfo{
{"IS_GRANTABLE", mysql.TypeVarchar, 3, 0, nil, nil},
}

var tableSchemaPrivilegesCols = []columnInfo{
{"GRANTEE", mysql.TypeVarchar, 81, mysql.NotNullFlag, nil, nil},
{"TABLE_CATALOG", mysql.TypeVarchar, 512, mysql.NotNullFlag, nil, nil},
{"TABLE_SCHEMA", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"PRIVILEGE_TYPE", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"IS_GRANTABLE", mysql.TypeVarchar, 3, mysql.NotNullFlag, nil, nil},
}

var tableTablePrivilegesCols = []columnInfo{
{"GRANTEE", mysql.TypeVarchar, 81, mysql.NotNullFlag, nil, nil},
{"TABLE_CATALOG", mysql.TypeVarchar, 512, mysql.NotNullFlag, nil, nil},
{"TABLE_SCHEMA", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"TABLE_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"PRIVILEGE_TYPE", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"IS_GRANTABLE", mysql.TypeVarchar, 3, mysql.NotNullFlag, nil, nil},
}

var tableColumnPrivilegesCols = []columnInfo{
{"GRANTEE", mysql.TypeVarchar, 81, mysql.NotNullFlag, nil, nil},
{"TABLE_CATALOG", mysql.TypeVarchar, 512, mysql.NotNullFlag, nil, nil},
{"TABLE_SCHEMA", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"TABLE_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"COLUMN_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"PRIVILEGE_TYPE", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"IS_GRANTABLE", mysql.TypeVarchar, 3, mysql.NotNullFlag, nil, nil},
}

var tableEnginesCols = []columnInfo{
{"ENGINE", mysql.TypeVarchar, 64, 0, nil, nil},
{"SUPPORT", mysql.TypeVarchar, 8, 0, nil, nil},
Expand Down Expand Up @@ -390,6 +428,98 @@ var tableRoutinesCols = []columnInfo{
{"DATABASE_COLLATION", mysql.TypeVarchar, 32, mysql.NotNullFlag, nil, nil},
}

var tableParametersCols = []columnInfo{
{"SPECIFIC_CATALOG", mysql.TypeVarchar, 512, mysql.NotNullFlag, nil, nil},
{"SPECIFIC_SCHEMA", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"SPECIFIC_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"ORDINAL_POSITION", mysql.TypeVarchar, 21, mysql.NotNullFlag, nil, nil},
{"PARAMETER_MODE", mysql.TypeVarchar, 5, 0, nil, nil},
{"PARAMETER_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"DATA_TYPE", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"CHARACTER_MAXIMUM_LENGTH", mysql.TypeVarchar, 21, 0, nil, nil},
{"CHARACTER_OCTET_LENGTH", mysql.TypeVarchar, 21, 0, nil, nil},
{"NUMERIC_PRECISION", mysql.TypeVarchar, 21, 0, nil, nil},
{"NUMERIC_SCALE", mysql.TypeVarchar, 21, 0, nil, nil},
{"DATETIME_PRECISION", mysql.TypeVarchar, 21, 0, nil, nil},
{"CHARACTER_SET_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"COLLATION_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"DTD_IDENTIFIER", mysql.TypeLongBlob, 0, mysql.NotNullFlag, nil, nil},
{"ROUTINE_TYPE", mysql.TypeVarchar, 9, mysql.NotNullFlag, nil, nil},
}

var tableEventsCols = []columnInfo{
{"EVENT_CATALOG", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"EVENT_SCHEMA", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"EVENT_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"DEFINER", mysql.TypeVarchar, 77, mysql.NotNullFlag, nil, nil},
{"TIME_ZONE", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"EVENT_BODY", mysql.TypeVarchar, 8, mysql.NotNullFlag, nil, nil},
{"EVENT_DEFINITION", mysql.TypeLongBlob, 0, 0, nil, nil},
{"EVENT_TYPE", mysql.TypeVarchar, 9, mysql.NotNullFlag, nil, nil},
{"EXECUTE_AT", mysql.TypeDatetime, 0, 0, nil, nil},
{"INTERVAL_VALUE", mysql.TypeVarchar, 256, 0, nil, nil},
{"INTERVAL_FIELD", mysql.TypeVarchar, 18, 0, nil, nil},
{"SQL_MODE", mysql.TypeVarchar, 8192, mysql.NotNullFlag, nil, nil},
{"STARTS", mysql.TypeDatetime, 0, 0, nil, nil},
{"ENDS", mysql.TypeDatetime, 0, 0, nil, nil},
{"STATUS", mysql.TypeVarchar, 18, mysql.NotNullFlag, nil, nil},
{"ON_COMPLETION", mysql.TypeVarchar, 12, mysql.NotNullFlag, nil, nil},
{"CREATED", mysql.TypeDatetime, 0, mysql.NotNullFlag, "0000-00-00 00:00:00", nil},
{"LAST_ALTERED", mysql.TypeDatetime, 0, mysql.NotNullFlag, "0000-00-00 00:00:00", nil},
{"LAST_EXECUTED", mysql.TypeDatetime, 0, 0, nil, nil},
{"EVENT_COMMENT", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"ORIGINATOR", mysql.TypeLong, 10, mysql.NotNullFlag, 0, nil},
{"CHARACTER_SET_CLIENT", mysql.TypeVarchar, 32, mysql.NotNullFlag, nil, nil},
{"COLLATION_CONNECTION", mysql.TypeVarchar, 32, mysql.NotNullFlag, nil, nil},
{"DATABASE_COLLATION", mysql.TypeVarchar, 32, mysql.NotNullFlag, nil, nil},
}

var tableGlobalStatusCols = []columnInfo{
{"VARIABLE_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"VARIABLE_VALUE", mysql.TypeVarchar, 1024, 0, nil, nil},
}

var tableGlobalVariablesCols = []columnInfo{
{"VARIABLE_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"VARIABLE_VALUE", mysql.TypeVarchar, 1024, 0, nil, nil},
}

var tableSessionStatusCols = []columnInfo{
{"VARIABLE_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
{"VARIABLE_VALUE", mysql.TypeVarchar, 1024, 0, nil, nil},
}

var tableOptimizerTraceCols = []columnInfo{
{"QUERY", mysql.TypeLongBlob, 0, mysql.NotNullFlag, "", nil},
{"TRACE", mysql.TypeLongBlob, 0, mysql.NotNullFlag, "", nil},
{"MISSING_BYTES_BEYOND_MAX_MEM_SIZE", mysql.TypeShort, 20, mysql.NotNullFlag, 0, nil},
{"INSUFFICIENT_PRIVILEGES", mysql.TypeTiny, 1, mysql.NotNullFlag, 0, nil},
}

var tableTableSpacesCols = []columnInfo{
{"TABLESPACE_NAME", mysql.TypeVarchar, 64, mysql.NotNullFlag, "", nil},
{"ENGINE", mysql.TypeVarchar, 64, mysql.NotNullFlag, "", nil},
{"TABLESPACE_TYPE", mysql.TypeVarchar, 64, 0, nil, nil},
{"LOGFILE_GROUP_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"EXTENT_SIZE", mysql.TypeLonglong, 21, 0, nil, nil},
{"AUTOEXTEND_SIZE", mysql.TypeLonglong, 21, 0, nil, nil},
{"MAXIMUM_SIZE", mysql.TypeLonglong, 21, 0, nil, nil},
{"NODEGROUP_ID", mysql.TypeLonglong, 21, 0, nil, nil},
{"TABLESPACE_COMMENT", mysql.TypeVarchar, 2048, 0, nil, nil},
}

var tableCollationCharacterSetApplicabilityCols = []columnInfo{
{"TABLESPACE_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"ENGINE", mysql.TypeVarchar, 64, 0, nil, nil},
{"TABLESPACE_TYPE", mysql.TypeVarchar, 64, 0, nil, nil},
{"LOGFILE_GROUP_NAME", mysql.TypeVarchar, 64, 0, nil, nil},
{"EXTENT_SIZE", mysql.TypeLong, 21, 0, nil, nil},
{"AUTOEXTEND_SIZE", mysql.TypeLong, 21, 0, nil, nil},
{"MAXIMUM_SIZE", mysql.TypeLong, 21, 0, nil, nil},
{"NODEGROUP_ID", mysql.TypeLong, 21, 0, nil, nil},
{"TABLESPACE_COMMENT", mysql.TypeVarchar, 2048, 0, nil, nil},
}

func dataForCharacterSets() (records [][]types.Datum) {
records = append(records,
types.MakeDatums("ascii", "ascii_general_ci", "US ASCII", 1),
Expand Down Expand Up @@ -718,25 +848,36 @@ func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum {
}

var tableNameToColumns = map[string]([]columnInfo){
tableSchemata: schemataCols,
tableTables: tablesCols,
tableColumns: columnsCols,
tableStatistics: statisticsCols,
tableCharacterSets: charsetCols,
tableCollations: collationsCols,
tableFiles: filesCols,
tableProfiling: profilingCols,
tablePartitions: partitionsCols,
tableKeyColumm: keyColumnUsageCols,
tableReferConst: referConstCols,
tableSessionVar: sessionVarCols,
tablePlugins: pluginsCols,
tableConstraints: tableConstraintsCols,
tableTriggers: tableTriggersCols,
tableUserPrivileges: tableUserPrivilegesCols,
tableEngines: tableEnginesCols,
tableViews: tableViewsCols,
tableRoutines: tableRoutinesCols,
tableSchemata: schemataCols,
tableTables: tablesCols,
tableColumns: columnsCols,
tableStatistics: statisticsCols,
tableCharacterSets: charsetCols,
tableCollations: collationsCols,
tableFiles: filesCols,
tableProfiling: profilingCols,
tablePartitions: partitionsCols,
tableKeyColumm: keyColumnUsageCols,
tableReferConst: referConstCols,
tableSessionVar: sessionVarCols,
tablePlugins: pluginsCols,
tableConstraints: tableConstraintsCols,
tableTriggers: tableTriggersCols,
tableUserPrivileges: tableUserPrivilegesCols,
tableSchemaPrivileges: tableSchemaPrivilegesCols,
tableTablePrivileges: tableTablePrivilegesCols,
tableColumnPrivileges: tableColumnPrivilegesCols,
tableEngines: tableEnginesCols,
tableViews: tableViewsCols,
tableRoutines: tableRoutinesCols,
tableParameters: tableParametersCols,
tableEvents: tableEventsCols,
tableGlobalStatus: tableGlobalStatusCols,
tableGlobalVariables: tableGlobalVariablesCols,
tableSessionStatus: tableSessionStatusCols,
tableOptimizerTrace: tableOptimizerTraceCols,
tableTableSpaces: tableTableSpacesCols,
tableCollationCharacterSetApplicability: tableCollationCharacterSetApplicabilityCols,
}

func createInfoSchemaTable(handle *Handle, meta *model.TableInfo) *infoschemaTable {
Expand Down Expand Up @@ -806,6 +947,18 @@ func (it *infoschemaTable) getRows(ctx context.Context, cols []*table.Column) (f
fullRows = dataForEngines()
case tableViews:
case tableRoutines:
// TODO: Fill the following tables.
case tableSchemaPrivileges:
case tableTablePrivileges:
case tableColumnPrivileges:
case tableParameters:
case tableEvents:
case tableGlobalStatus:
case tableGlobalVariables:
case tableSessionStatus:
case tableOptimizerTrace:
case tableTableSpaces:
case tableCollationCharacterSetApplicability:
}
if err != nil {
return nil, errors.Trace(err)
Expand Down

0 comments on commit 73c9e12

Please sign in to comment.