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

infoschema: Migrate the infoschema's retrieving data logic for 'CharacterSets/Collations' to executor #15103

Merged
merged 3 commits into from
Mar 3, 2020
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: 5 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,11 @@ func (b *executorBuilder) buildMemTable(v *plannercore.PhysicalMemTable) Executo
timeRange: v.QueryTimeRange,
},
}
case strings.ToLower(infoschema.TableSchemata), strings.ToLower(infoschema.TableViews), strings.ToLower(infoschema.TableEngines):
case strings.ToLower(infoschema.TableSchemata),
strings.ToLower(infoschema.TableViews),
strings.ToLower(infoschema.TableEngines),
strings.ToLower(infoschema.TableCollations),
strings.ToLower(infoschema.TableCharacterSets):
return &MemTableReaderExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
retriever: &memtableRetriever{
Expand Down
29 changes: 29 additions & 0 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"sort"

"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -54,6 +55,10 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
e.rows, err = dataForViews(sctx, dbs)
case infoschema.TableEngines:
e.rows = dataForEngines()
case infoschema.TableCharacterSets:
e.rows = dataForCharacterSets()
case infoschema.TableCollations:
e.rows = dataForCollations()
}
if err != nil {
return nil, err
Expand Down Expand Up @@ -169,3 +174,27 @@ func dataForEngines() (rows [][]types.Datum) {
)
return rows
}

func dataForCharacterSets() (records [][]types.Datum) {
charsets := charset.GetSupportedCharsets()
for _, charset := range charsets {
records = append(records,
types.MakeDatums(charset.Name, charset.DefaultCollation, charset.Desc, charset.Maxlen),
)
}
return records
}

func dataForCollations() (records [][]types.Datum) {
collations := charset.GetSupportedCollations()
for _, collation := range collations {
isDefault := ""
if collation.IsDefault {
isDefault = "Yes"
}
records = append(records,
types.MakeDatums(collation.Name, collation.CharsetName, collation.ID, isDefault, "Yes", 1),
)
}
return records
}
13 changes: 13 additions & 0 deletions executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,16 @@ func (s *testInfoschemaTableSuite) TestEngines(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustQuery("select * from information_schema.ENGINES;").Check(testkit.Rows("InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES"))
}

func (s *testInfoschemaTableSuite) TestCharacterSetCollations(c *C) {
tk := testkit.NewTestKit(c, s.store)

// The description column is not important
tk.MustQuery("SELECT default_collate_name, maxlen FROM information_schema.character_sets ORDER BY character_set_name").Check(
testkit.Rows("ascii_bin 1", "binary 1", "latin1_bin 1", "utf8_bin 3", "utf8mb4_bin 4"))

// The is_default column is not important
// but the id's are used by client libraries and must be stable
tk.MustQuery("SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name").Check(
testkit.Rows("ascii 65 1", "binary 63 1", "latin1 47 1", "utf8 83 1", "utf8mb4 46 1"))
}
57 changes: 9 additions & 48 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ const (
tableColumns = "COLUMNS"
tableColumnStatistics = "COLUMN_STATISTICS"
tableStatistics = "STATISTICS"
tableCharacterSets = "CHARACTER_SETS"
tableCollations = "COLLATIONS"
tableFiles = "FILES"
// TableCharacterSets is the string constant of infoschema charactersets memory table
TableCharacterSets = "CHARACTER_SETS"
// TableCollations is the string constant of infoschema collations memory table
TableCollations = "COLLATIONS"
tableFiles = "FILES"
// CatalogVal is the string constant of TABLE_CATALOG
CatalogVal = "def"
tableProfiling = "PROFILING"
Expand Down Expand Up @@ -128,8 +130,8 @@ var tableIDMap = map[string]int64{
tableColumns: autoid.InformationSchemaDBID + 3,
tableColumnStatistics: autoid.InformationSchemaDBID + 4,
tableStatistics: autoid.InformationSchemaDBID + 5,
tableCharacterSets: autoid.InformationSchemaDBID + 6,
tableCollations: autoid.InformationSchemaDBID + 7,
TableCharacterSets: autoid.InformationSchemaDBID + 6,
TableCollations: autoid.InformationSchemaDBID + 7,
tableFiles: autoid.InformationSchemaDBID + 8,
CatalogVal: autoid.InformationSchemaDBID + 9,
tableProfiling: autoid.InformationSchemaDBID + 10,
Expand Down Expand Up @@ -1123,43 +1125,6 @@ func dataForTiKVStoreStatus(ctx sessionctx.Context) (records [][]types.Datum, er
return records, nil
}

func dataForCharacterSets() (records [][]types.Datum) {

charsets := charset.GetSupportedCharsets()

for _, charset := range charsets {

records = append(records,
types.MakeDatums(charset.Name, charset.DefaultCollation, charset.Desc, charset.Maxlen),
)

}

return records

}

func dataForCollations() (records [][]types.Datum) {

collations := charset.GetSupportedCollations()

for _, collation := range collations {

isDefault := ""
if collation.IsDefault {
isDefault = "Yes"
}

records = append(records,
types.MakeDatums(collation.Name, collation.CharsetName, collation.ID, isDefault, "Yes", 1),
)

}

return records

}

func dataForCollationCharacterSetApplicability() (records [][]types.Datum) {

collations := charset.GetSupportedCollations()
Expand Down Expand Up @@ -2391,8 +2356,8 @@ var tableNameToColumns = map[string][]columnInfo{
tableColumns: columnsCols,
tableColumnStatistics: columnStatisticsCols,
tableStatistics: statisticsCols,
tableCharacterSets: charsetCols,
tableCollations: collationsCols,
TableCharacterSets: charsetCols,
TableCollations: collationsCols,
tableFiles: filesCols,
tableProfiling: profilingCols,
tablePartitions: partitionsCols,
Expand Down Expand Up @@ -2486,10 +2451,6 @@ func (it *infoschemaTable) getRows(ctx sessionctx.Context, cols []*table.Column)
fullRows = dataForColumns(ctx, dbs)
case tableStatistics:
fullRows = dataForStatistics(ctx, dbs)
case tableCharacterSets:
fullRows = dataForCharacterSets()
case tableCollations:
fullRows = dataForCollations()
case tableSessionVar:
fullRows, err = dataForSessionVar(ctx)
case tableConstraints:
Expand Down
9 changes: 0 additions & 9 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,6 @@ func (s *testTableSuite) TestDataForTableStatsField(c *C) {
func (s *testTableSuite) TestCharacterSetCollations(c *C) {
tk := testkit.NewTestKit(c, s.store)

// The description column is not important
tk.MustQuery("SELECT default_collate_name, maxlen FROM information_schema.character_sets ORDER BY character_set_name").Check(
testkit.Rows("ascii_bin 1", "binary 1", "latin1_bin 1", "utf8_bin 3", "utf8mb4_bin 4"))

// The is_default column is not important
// but the id's are used by client libraries and must be stable
tk.MustQuery("SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name").Check(
testkit.Rows("ascii 65 1", "binary 63 1", "latin1 47 1", "utf8 83 1", "utf8mb4 46 1"))

// Test charset/collation in information_schema.COLUMNS table.
tk.MustExec("DROP DATABASE IF EXISTS charset_collate_test")
tk.MustExec("CREATE DATABASE charset_collate_test; USE charset_collate_test")
Expand Down