Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: explain mysql56 (#12691)

Danny Xu6adb6c2a3831
diff --git a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
index c8e40a27d6..cee40dc146 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
@@ -175,6 +175,10 @@ func getInsertRows(res []any) (int64, error) {
if len(res) != 3 {
return 0, errors.Errorf("expected 3 but got %d", len(res))
}
+ columns, ok := res[0].([]string)
+ if !ok {
+ return 0, errors.Errorf("expected []string but got %t", res[0])
+ }
rowList, ok := res[2].([]any)
if !ok {
return 0, errors.Errorf("expected []any but got %t", res[2])
@@ -202,15 +206,17 @@ func getInsertRows(res []any) (int64, error) {
// | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |
// +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+
+ rowsIndex, err := getColumnIndex(columns, "rows")
+ if err != nil {
+ return 0, errors.Errorf("failed to find rows column")
+ }
+
for _, rowAny := range rowList {
row, ok := rowAny.([]any)
if !ok {
return 0, errors.Errorf("expected []any but got %t", row)
}
- if len(row) != 12 {
- return 0, errors.Errorf("expected 12 but got %d", len(row))
- }
- switch col := row[9].(type) {
+ switch col := row[rowsIndex].(type) {
case int:
return int64(col), nil
case int32:
diff --git a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
index 46cab81a13..ca087d2ada 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
@@ -148,6 +148,10 @@ func getRows(res []any) (int64, error) {
if len(res) != 3 {
return 0, errors.Errorf("expected 3 but got %d", len(res))
}
+ columns, ok := res[0].([]string)
+ if !ok {
+ return 0, errors.Errorf("expected []string but got %t", res[0])
+ }
rowList, ok := res[2].([]any)
if !ok {
return 0, errors.Errorf("expected []any but got %t", res[2])
@@ -174,16 +178,18 @@ func getRows(res []any) (int64, error) {
// | 1 | INSERT | td | NULL | ALL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
// | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |
// +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+
+ rowsIndex, err := getColumnIndex(columns, "rows")
+ if err != nil {
+ return 0, errors.Errorf("failed to find rows column")
+ }
for _, rowAny := range rowList {
row, ok := rowAny.([]any)
if !ok {
return 0, errors.Errorf("expected []any but got %t", row)
}
- if len(row) != 12 {
- return 0, errors.Errorf("expected 12 but got %d", len(row))
- }
- switch col := row[9].(type) {
+
+ switch col := row[rowsIndex].(type) {
case int:
return int64(col), nil
case int32:
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
index cd2d0c3afc..d256dab4d2 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
@@ -124,6 +124,10 @@ func hasUsingFilesortInExtraColumn(res []any) (bool, string, error) {
if len(res) != 3 {
return false, "", errors.Errorf("expected 3 but got %d", len(res))
}
+ columns, ok := res[0].([]string)
+ if !ok {
+ return false, "", errors.Errorf("expected []string but got %t", res[0])
+ }
rowList, ok := res[2].([]any)
if !ok {
return false, "", errors.Errorf("expected []any but got %t", res[2])
@@ -153,21 +157,28 @@ func hasUsingFilesortInExtraColumn(res []any) (bool, string, error) {
// | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |
// +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+
+ extraIndex, err := getColumnIndex(columns, "Extra")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+ tableIndex, err := getColumnIndex(columns, "table")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+
var tables []string
for _, rowAny := range rowList {
row, ok := rowAny.([]any)
if !ok {
return false, "", errors.Errorf("expected []any but got %t", row)
}
- if len(row) != 12 {
- return false, "", errors.Errorf("expected 12 but got %d", len(row))
- }
- extra, ok := row[11].(string)
+
+ extra, ok := row[extraIndex].(string)
if !ok {
return false, "", nil
}
if strings.Contains(extra, "Using filesort") {
- tables = append(tables, row[2].(string))
+ tables = append(tables, row[tableIndex].(string))
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
index 856611e9b6..c88c70757f 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
@@ -124,6 +124,10 @@ func hasUsingTemporaryInExtraColumn(res []any) (bool, string, error) {
if len(res) != 3 {
return false, "", errors.Errorf("expected 3 but got %d", len(res))
}
+ columns, ok := res[0].([]string)
+ if !ok {
+ return false, "", errors.Errorf("expected []string but got %t", res[0])
+ }
rowList, ok := res[2].([]any)
if !ok {
return false, "", errors.Errorf("expected []any but got %t", res[2])
@@ -153,21 +157,27 @@ func hasUsingTemporaryInExtraColumn(res []any) (bool, string, error) {
// | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |
// +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+
+ extraIndex, err := getColumnIndex(columns, "Extra")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+ tableIndex, err := getColumnIndex(columns, "table")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+
var tables []string
for _, rowAny := range rowList {
row, ok := rowAny.([]any)
if !ok {
return false, "", errors.Errorf("expected []any but got %t", row)
}
- if len(row) != 12 {
- return false, "", errors.Errorf("expected 12 but got %d", len(row))
- }
- extra, ok := row[11].(string)
+ extra, ok := row[extraIndex].(string)
if !ok {
return false, "", nil
}
if strings.Contains(extra, "Using temporary") {
- tables = append(tables, row[2].(string))
+ tables = append(tables, row[tableIndex].(string))
}
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go b/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
index d7e8c0dd1a..bf9fb5f2b7 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
@@ -195,6 +195,10 @@ func getQueryExplainTypes(res []any) ([]ExplainType, error) {
if len(res) != 3 {
return nil, errors.Errorf("expected 3 but got %d", len(res))
}
+ columns, ok := res[0].([]string)
+ if !ok {
+ return nil, errors.Errorf("expected []string but got %t", res[0])
+ }
rowList, ok := res[2].([]any)
if !ok {
return nil, errors.Errorf("expected []any but got %t", res[2])
@@ -223,6 +227,10 @@ func getQueryExplainTypes(res []any) ([]ExplainType, error) {
// | 1 | INSERT | td | NULL | ALL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
// | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |
// +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+
+ typeIndex, err := getColumnIndex(columns, "type")
+ if err != nil {
+ return nil, errors.Errorf("failed to find rows column")
+ }
explainTypes := []ExplainType{}
for _, rowAny := range rowList {
@@ -230,10 +238,7 @@ func getQueryExplainTypes(res []any) ([]ExplainType, error) {
if !ok {
return nil, errors.Errorf("expected []any but got %t", row)
}
- if len(row) != 12 {
- return nil, errors.Errorf("expected 12 but got %d", len(row))
- }
- explainType, ok := row[4].(string)
+ explainType, ok := row[typeIndex].(string)
if !ok {
// Skip the row if the type column is not a string.
continue
diff --git a/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go b/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
index ae6d26c02b..4a32eb14d4 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
@@ -118,6 +118,10 @@ func hasTableFullScan(res []any) (bool, string, error) {
if len(res) != 3 {
return false, "", errors.Errorf("expected 3 but got %d", len(res))
}
+ columns, ok := res[0].([]string)
+ if !ok {
+ return false, "", errors.Errorf("expected []string but got %t", res[0])
+ }
rowList, ok := res[2].([]any)
if !ok {
return false, "", errors.Errorf("expected []any but got %t", res[2])
@@ -147,29 +151,38 @@ func hasTableFullScan(res []any) (bool, string, error) {
// | 1 | SIMPLE | td | NULL | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary |
// +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-----------------+
- var tables []string
+ tableIndex, err := getColumnIndex(columns, "table")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+ typeIndex, err := getColumnIndex(columns, "type")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+ extraIndex, err := getColumnIndex(columns, "Extra")
+ if err != nil {
+ return false, "", errors.Errorf("failed to find rows column")
+ }
+ var tables []string
for _, rowAny := range rowList {
row, ok := rowAny.([]any)
if !ok {
return false, "", errors.Errorf("expected []any but got %t", row)
}
- if len(row) != 12 {
- return false, "", errors.Errorf("expected 12 but got %d", len(row))
- }
- if row[4] == "ALL" {
- tables = append(tables, row[2].(string))
+ if row[typeIndex] == "ALL" {
+ tables = append(tables, row[tableIndex].(string))
continue
}
- if row[4] == "index" {
- extra, ok := row[11].(string)
+ if row[typeIndex] == "index" {
+ extra, ok := row[extraIndex].(string)
if !ok {
return false, "", nil
}
if strings.Contains(extra, "Using where") || strings.Contains(extra, "Using index condition") {
continue
}
- tables = append(tables, row[2].(string))
+ tables = append(tables, row[tableIndex].(string))
continue
}
}
diff --git a/backend/plugin/advisor/mysql/common.go b/backend/plugin/advisor/mysql/common.go
new file mode 100644
index 0000000000..935302540f
--- /dev/null
+++ b/backend/plugin/advisor/mysql/common.go
@@ -0,0 +1,12 @@
+package mysql
+
+import "github.com/pkg/errors"
+
+func getColumnIndex(columns []string, name string) (int, error) {
+ for i, columnName := range columns {
+ if columnName == name {
+ return i, nil
+ }
+ }
+ return -1, errors.Errorf("failed to find column %q", name)
+}