Skip to content

Commit

Permalink
infoschema: fix not null flag does not work (pingcap#6048)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhexuany authored and coocood committed Mar 19, 2018
1 parent daa866c commit 6d13308
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
13 changes: 10 additions & 3 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func buildColumnInfo(tableName string, col columnInfo) *model.ColumnInfo {
if col.tp == mysql.TypeVarchar || col.tp == mysql.TypeBlob {
mCharset = mysql.DefaultCharset
mCollation = mysql.DefaultCollationName
mFlag = 0
mFlag = col.flag
}
fieldType := types.FieldType{
Charset: mCharset,
Expand Down Expand Up @@ -108,6 +108,8 @@ func buildTableMeta(tableName string, cs []columnInfo) *model.TableInfo {
Name: model.NewCIStr(tableName),
Columns: cols,
State: model.StatePublic,
Charset: mysql.DefaultCharset,
Collate: mysql.DefaultCollationName,
}
}

Expand Down Expand Up @@ -137,7 +139,7 @@ var tablesCols = []columnInfo{
{"CREATE_TIME", mysql.TypeDatetime, 19, 0, nil, nil},
{"UPDATE_TIME", mysql.TypeDatetime, 19, 0, nil, nil},
{"CHECK_TIME", mysql.TypeDatetime, 19, 0, nil, nil},
{"TABLE_COLLATION", mysql.TypeVarchar, 32, 0, nil, nil},
{"TABLE_COLLATION", mysql.TypeVarchar, 32, mysql.NotNullFlag, "utf8_bin", nil},
{"CHECK_SUM", mysql.TypeLonglong, 21, 0, nil, nil},
{"CREATE_OPTIONS", mysql.TypeVarchar, 255, 0, nil, nil},
{"TABLE_COMMENT", mysql.TypeVarchar, 2048, 0, nil, nil},
Expand Down Expand Up @@ -540,6 +542,7 @@ func dataForCollationCharacterSetApplicability() (records [][]types.Datum) {
types.MakeDatums("binary", "binary"),
types.MakeDatums("latin1_swedish_ci", "latin1"),
types.MakeDatums("utf8_general_ci", "utf8"),
types.MakeDatums("utf8_bin", "utf8"),
types.MakeDatums("utf8mb4_general_ci", "utf8mb4"),
)
return records
Expand Down Expand Up @@ -637,6 +640,10 @@ func dataForTables(ctx sessionctx.Context, schemas []*model.DBInfo) [][]types.Da
createTimeTp := tablesCols[15].tp
for _, schema := range schemas {
for _, table := range schema.Tables {
collation := table.Collate
if collation == "" {
collation = charset.CollationUTF8
}
createTime := types.Time{
Time: types.FromGoTime(table.GetUpdateTime()),
Type: createTimeTp,
Expand All @@ -659,7 +666,7 @@ func dataForTables(ctx sessionctx.Context, schemas []*model.DBInfo) [][]types.Da
createTime, // CREATE_TIME
nil, // UPDATE_TIME
nil, // CHECK_TIME
table.Collate, // TABLE_COLLATION
collation, // TABLE_COLLATION
nil, // CHECKSUM
"", // CREATE_OPTIONS
table.Comment, // TABLE_COMMENT
Expand Down
4 changes: 2 additions & 2 deletions model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (*testModelSuite) TestModelBasic(c *C) {
ID: 1,
Name: NewCIStr("t"),
Charset: "utf8",
Collate: "utf8",
Collate: "utf8_bin",
Columns: []*ColumnInfo{column},
Indices: []*IndexInfo{index},
ForeignKeys: []*FKInfo{fk},
Expand All @@ -83,7 +83,7 @@ func (*testModelSuite) TestModelBasic(c *C) {
ID: 1,
Name: NewCIStr("test"),
Charset: "utf8",
Collate: "utf8",
Collate: "utf8_bin",
Tables: []*TableInfo{table},
}

Expand Down
4 changes: 2 additions & 2 deletions perfschema/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func (ps *PerfSchema) buildModel(tbName string, colNames []string, cols []column

ps.tables[tbName] = &model.TableInfo{
Name: model.NewCIStr(tbName),
Charset: "utf8",
Collate: "utf8",
Charset: charset.CharsetBin,
Collate: charset.CollationBin,
Columns: rcols,
}
}
Expand Down
27 changes: 14 additions & 13 deletions util/charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ var charsetInfos = []*Charset{
{CharsetBin, CollationBin, make(map[string]*Collation), "binary", 1},
}

func init() {
for _, c := range charsetInfos {
charsets[c.Name] = c
}
for _, c := range collations {
charset, ok := charsets[c.CharsetName]
if !ok {
continue
}
charset.Collations[c.Name] = c
}
}

// Desc is a charset description.
type Desc struct {
Name string
Expand Down Expand Up @@ -414,3 +401,17 @@ var collations = []*Collation{
{246, "utf8mb4", "utf8mb4_unicode_520_ci", false},
{247, "utf8mb4", "utf8mb4_vietnamese_ci", false},
}

// init method always puts to the end of file.
func init() {
for _, c := range charsetInfos {
charsets[c.Name] = c
}
for _, c := range collations {
charset, ok := charsets[c.CharsetName]
if !ok {
continue
}
charset.Collations[c.Name] = c
}
}

0 comments on commit 6d13308

Please sign in to comment.