@@ -51,6 +51,7 @@ type Index struct {
51
51
Fields []string
52
52
Unique bool
53
53
Visible bool
54
+ Expression string // MySQL 8.0.16+
54
55
}
55
56
56
57
// IndexField holds raw index information as defined in INFORMATION_SCHEMA table
@@ -67,7 +68,8 @@ type IndexField struct {
67
68
Comment string
68
69
IndexComment string
69
70
NonUnique bool
70
- Visible bool // MySQL 8.0+
71
+ Visible string // MySQL 8.0+
72
+ Expression sql.NullString // MySQL 8.0.16+
71
73
}
72
74
73
75
// Constraint holds Foreign Keys information
@@ -262,15 +264,18 @@ func getIndexes(db *sql.DB, schema, tableName string) (map[string]Index, error)
262
264
263
265
for rows .Next () {
264
266
var i IndexField
265
- var table , visible string
267
+ var table , string
266
268
fields := []interface {}{& table , & i .NonUnique , & i .KeyName , & i .SeqInIndex ,
267
269
& i .ColumnName , & i .Collation , & i .Cardinality , & i .SubPart ,
268
270
& i .Packed , & i .Null , & i .IndexType , & i .Comment , & i .IndexComment ,
269
271
}
270
272
271
273
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 )
274
279
}
275
280
276
281
err = rows .Scan (fields ... )
@@ -279,10 +284,11 @@ func getIndexes(db *sql.DB, schema, tableName string) (map[string]Index, error)
279
284
}
280
285
if index , ok := indexes [i .KeyName ]; ! ok {
281
286
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 ,
286
292
}
287
293
288
294
} else {
0 commit comments