Skip to content

Commit 9e592f7

Browse files
Merge pull request #30 from dutow/8016fix
Handle 8.0.16 expression indexes. Fixes #27.
2 parents ec5066c + 88d4bd1 commit 9e592f7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tableparser/tableparser.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type Index struct {
5151
Fields []string
5252
Unique bool
5353
Visible bool
54+
Expression string // MySQL 8.0.16+
5455
}
5556

5657
// IndexField holds raw index information as defined in INFORMATION_SCHEMA table
@@ -67,7 +68,8 @@ type IndexField struct {
6768
Comment string
6869
IndexComment string
6970
NonUnique bool
70-
Visible bool // MySQL 8.0+
71+
Visible string // MySQL 8.0+
72+
Expression sql.NullString // MySQL 8.0.16+
7173
}
7274

7375
// Constraint holds Foreign Keys information
@@ -262,15 +264,18 @@ func getIndexes(db *sql.DB, schema, tableName string) (map[string]Index, error)
262264

263265
for rows.Next() {
264266
var i IndexField
265-
var table, visible string
267+
var table, string
266268
fields := []interface{}{&table, &i.NonUnique, &i.KeyName, &i.SeqInIndex,
267269
&i.ColumnName, &i.Collation, &i.Cardinality, &i.SubPart,
268270
&i.Packed, &i.Null, &i.IndexType, &i.Comment, &i.IndexComment,
269271
}
270272

271273
cols, err := rows.Columns()
272-
if err == nil && len(cols) == 14 && cols[13] == "Visible" {
273-
fields = append(fields, &visible)
274+
if err == nil && len(cols) >= 14 && cols[13] == "Visible" {
275+
fields = append(fields, &i.Visible)
276+
}
277+
if err == nil && len(cols) >= 15 && cols[14] == "Expression" {
278+
fields = append(fields, &i.Expression)
274279
}
275280

276281
err = rows.Scan(fields...)
@@ -279,10 +284,11 @@ func getIndexes(db *sql.DB, schema, tableName string) (map[string]Index, error)
279284
}
280285
if index, ok := indexes[i.KeyName]; !ok {
281286
indexes[i.KeyName] = Index{
282-
Name: i.KeyName,
283-
Unique: !i.NonUnique,
284-
Fields: []string{i.ColumnName},
285-
Visible: visible == "YES" || visible == "",
287+
Name: i.KeyName,
288+
Unique: !i.NonUnique,
289+
Fields: []string{i.ColumnName},
290+
Visible: i.Visible == "YES" || visible == "",
291+
Expression: i.Expression.String,
286292
}
287293

288294
} else {

0 commit comments

Comments
 (0)