Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: estimate MySQL affected rows from the JSON plan's DML target node
rebelice7c3c2081916e
diff --git a/backend/plugin/advisor/mysql/mysql_rules_test.go b/backend/plugin/advisor/mysql/mysql_rules_test.goindex 442bc315cd..38e06e6d43 100644--- a/backend/plugin/advisor/mysql/mysql_rules_test.go+++ b/backend/plugin/advisor/mysql/mysql_rules_test.go@@ -5,6 +5,7 @@ import ("database/sql""database/sql/driver""io"+ "strings""testing""github.com/stretchr/testify/require"@@ -18,6 +19,10 @@ import (var testMySQLAdvisorExplainRows [][]driver.Value+// testMySQLAdvisorExplainJSON is returned for `EXPLAIN FORMAT=JSON` queries; when+// empty, the JSON query returns no rows and the advisor falls back to the tabular rows.+var testMySQLAdvisorExplainJSON string+func init() {sql.Register("test_mysql_advisor_explain", testMySQLAdvisorExplainDriver{})}@@ -42,8 +47,18 @@ func (testMySQLAdvisorExplainConn) Begin() (driver.Tx, error) {return testMySQLAdvisorExplainTx{}, nil}-func (testMySQLAdvisorExplainConn) QueryContext(context.Context, string, []driver.NamedValue) (driver.Rows, error) {- return &testMySQLAdvisorExplainResultRows{rows: testMySQLAdvisorExplainRows}, nil+func (testMySQLAdvisorExplainConn) QueryContext(_ context.Context, query string, _ []driver.NamedValue) (driver.Rows, error) {+ if strings.HasPrefix(query, "EXPLAIN FORMAT=JSON") {+ var rows [][]driver.Value+ if testMySQLAdvisorExplainJSON != "" {+ rows = [][]driver.Value{{testMySQLAdvisorExplainJSON}}+ }+ return &testMySQLAdvisorExplainResultRows{columns: []string{"EXPLAIN"}, rows: rows}, nil+ }+ return &testMySQLAdvisorExplainResultRows{+ columns: []string{"id", "select_type", "table", "type", "rows", "filtered"},+ rows: testMySQLAdvisorExplainRows,+ }, nil}type testMySQLAdvisorExplainTx struct{}@@ -57,12 +72,13 @@ func (testMySQLAdvisorExplainTx) Rollback() error {}type testMySQLAdvisorExplainResultRows struct {- rows [][]driver.Value- idx int+ columns []string+ rows [][]driver.Value+ idx int}-func (*testMySQLAdvisorExplainResultRows) Columns() []string {- return []string{"id", "select_type", "table", "type", "rows", "filtered"}+func (r *testMySQLAdvisorExplainResultRows) Columns() []string {+ return r.columns}func (*testMySQLAdvisorExplainResultRows) Close() error {@@ -156,7 +172,48 @@ func TestMySQLRules(t *testing.T) {}}+func TestMySQLAffectedRowLimitAdvisorUsesJSONPlanTargetNode(t *testing.T) {+ // The tabular EXPLAIN's first row is a 100232-row driving-table scan; the JSON+ // plan flags the update target whose cumulative estimate is 1144 (BYT-9858).+ testMySQLAdvisorExplainJSON = `{"query_block":{"select_id":1,"nested_loop":[+ {"table":{"table_name":"t","access_type":"ALL","rows_examined_per_scan":100232,"rows_produced_per_join":3006,"filtered":"3.00"}},+ {"table":{"update":true,"table_name":"o","access_type":"ref","rows_examined_per_scan":3,"rows_produced_per_join":1144,"filtered":"10.00"}}+ ]}}`+ testMySQLAdvisorExplainRows = [][]driver.Value{+ {int64(1), "SIMPLE", "t", "ALL", int64(100232), "3.00"},+ {int64(1), "UPDATE", "o", "ref", int64(3), "10.00"},+ }+ defer func() { testMySQLAdvisorExplainJSON = "" }()++ db, err := sql.Open("test_mysql_advisor_explain", "")+ require.NoError(t, err)+ defer db.Close()++ sm := sheet.NewManager()+ adviceList, err := advisor.SQLReviewCheck(context.Background(), sm, "UPDATE o SET c = 1 WHERE c IS NULL AND EXISTS (SELECT 1 FROM t WHERE t.k = o.k);", []*storepb.SQLReviewRule{+ {+ Type: storepb.SQLReviewRule_STATEMENT_AFFECTED_ROW_LIMIT,+ Level: storepb.SQLReviewRule_WARNING,+ Engine: storepb.Engine_MYSQL,+ Payload: &storepb.SQLReviewRule_NumberPayload{+ NumberPayload: &storepb.SQLReviewRule_NumberRulePayload{+ Number: 2000,+ },+ },+ },+ }, advisor.Context{+ DBType: storepb.Engine_MYSQL,+ Driver: db,+ NoAppendBuiltin: true,+ })+ require.NoError(t, err)+ // 1144 is below the 2000 limit; the legacy first-"rows" heuristic would have+ // reported 100232 and produced advice.+ require.Empty(t, adviceList)+}+func TestMySQLRowLimitAdvisorsCapExplainEstimateByLimit(t *testing.T) {+ testMySQLAdvisorExplainJSON = ""testMySQLAdvisorExplainRows = [][]driver.Value{{int64(1), "SIMPLE", "td", "ALL", int64(1000), "100.00"},}diff --git a/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.go b/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.goindex 511dbe7ccb..fa88b062aa 100644--- a/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.go+++ b/backend/plugin/advisor/mysql/rule_statement_affected_row_limit.go@@ -71,18 +71,26 @@ func (*StatementAffectedRowLimitAdvisor) Check(ctx context.Context, checkCtx advline := baseLine + int(mysqlparser.ByteOffsetToRunePosition(stmt.Text, contentStartIndex(stmt.Text)).Line)explainCount++- res, err := advisor.Query(ctx, advisor.QueryContext{}, driver, storepb.Engine_MYSQL, fmt.Sprintf("EXPLAIN %s", text))- if err != nil {- advice = append(advice, &storepb.Advice{- Status: level,- Code: code.StatementAffectedRowExceedsLimit.Int32(),- Title: title,- Content: fmt.Sprintf("\"%s\" dry runs failed: %s", text, err.Error()),- StartPosition: common.ConvertANTLRLineToPosition(line),- })- } else {- rowCount, err := getRows(res)+ // Prefer the JSON query plan: the tabular EXPLAIN's first "rows" value may+ // be the scan estimate of a driving table unrelated to the DML target+ // (BYT-9858). Fall back to the tabular heuristic when the JSON plan yields+ // no flagged target node.+ var rowCount int64+ counted := false+ if res, err := advisor.Query(ctx, advisor.QueryContext{}, driver, storepb.Engine_MYSQL, fmt.Sprintf("EXPLAIN FORMAT=JSON %s", text)); err == nil {+ rowCount, counted = getRowsFromJSONPlan(res)+ }+ if !counted {+ res, err := advisor.Query(ctx, advisor.QueryContext{}, driver, storepb.Engine_MYSQL, fmt.Sprintf("EXPLAIN %s", text))if err != nil {+ advice = append(advice, &storepb.Advice{+ Status: level,+ Code: code.StatementAffectedRowExceedsLimit.Int32(),+ Title: title,+ Content: fmt.Sprintf("\"%s\" dry runs failed: %s", text, err.Error()),+ StartPosition: common.ConvertANTLRLineToPosition(line),+ })+ } else if rowCount, err = getRows(res); err != nil {advice = append(advice, &storepb.Advice{Status: level,Code: code.Internal.Int32(),@@ -90,7 +98,12 @@ func (*StatementAffectedRowLimitAdvisor) Check(ctx context.Context, checkCtx advContent: fmt.Sprintf("failed to get row count for \"%s\": %s", text, err.Error()),StartPosition: common.ConvertANTLRLineToPosition(line),})- } else if rowCount = capRowsByLimit(rowCount, limit); rowCount > int64(maxRow) {+ } else {+ counted = true+ }+ }+ if counted {+ if rowCount = capRowsByLimit(rowCount, limit); rowCount > int64(maxRow) {advice = append(advice, &storepb.Advice{Status: level,Code: code.StatementAffectedRowExceedsLimit.Int32(),@@ -110,6 +123,31 @@ func (*StatementAffectedRowLimitAdvisor) Check(ctx context.Context, checkCtx advreturn advice, nil}+// getRowsFromJSONPlan extracts the affected-row estimate from an+// `EXPLAIN FORMAT=JSON` query result, whose single column holds the JSON plan.+func getRowsFromJSONPlan(res []any) (int64, bool) {+ if len(res) != 3 {+ return 0, false+ }+ rowList, ok := res[2].([]any)+ if !ok {+ return 0, false+ }+ var plan strings.Builder+ for _, rowAny := range rowList {+ row, ok := rowAny.([]any)+ if !ok {+ return 0, false+ }+ for _, col := range row {+ if s, ok := col.(string); ok {+ plan.WriteString(s)+ }+ }+ }+ return mysqlparser.GetEstimatedAffectedRowsFromExplainJSON(plan.String())+}+func getRows(res []any) (int64, error) {// the res struct is []any{columnName, columnTable, rowDataList}if len(res) != 3 {diff --git a/backend/plugin/db/mysql/stats.go b/backend/plugin/db/mysql/stats.goindex 74c6a7042a..2c74228aa8 100644--- a/backend/plugin/db/mysql/stats.go+++ b/backend/plugin/db/mysql/stats.go@@ -20,6 +20,14 @@ func (d *Driver) CountAffectedRows(ctx context.Context, statement string) (int64return countAffectedRowsForOceanBase(ctx, d.db, statement)}+ // Prefer the JSON query plan: the tabular EXPLAIN's first "rows" value may be the+ // scan estimate of a driving table unrelated to the DML target (BYT-9858). Fall+ // back to the tabular heuristic when no flagged target node is found (e.g. INSERT+ // plans, or servers that don't mark the target).+ if count, ok := d.countAffectedRowsFromJSONPlan(ctx, statement); ok {+ return capAffectedRowsByLimit(count, statement), nil+ }+explainSQL := fmt.Sprintf("EXPLAIN %s", statement)rows, err := d.db.QueryContext(ctx, explainSQL)if err != nil {@@ -71,6 +79,29 @@ func (d *Driver) CountAffectedRows(ctx context.Context, statement string) (int64return 0, nil}+func (d *Driver) countAffectedRowsFromJSONPlan(ctx context.Context, statement string) (int64, bool) {+ rows, err := d.db.QueryContext(ctx, fmt.Sprintf("EXPLAIN FORMAT=JSON %s", statement))+ if err != nil {+ return 0, false+ }+ defer rows.Close()++ var plan strings.Builder+ for rows.Next() {+ var planColumn sql.NullString+ if err := rows.Scan(&planColumn); err != nil {+ return 0, false+ }+ if planColumn.Valid {+ plan.WriteString(planColumn.String)+ }+ }+ if err := rows.Err(); err != nil {+ return 0, false+ }+ return mysqlparser.GetEstimatedAffectedRowsFromExplainJSON(plan.String())+}+func capAffectedRowsByLimit(count int64, statement string) int64 {limit, ok := affectedRowsLimit(statement)if !ok || limit >= count {diff --git a/backend/plugin/db/mysql/stats_test.go b/backend/plugin/db/mysql/stats_test.goindex 5a1cb119ae..0ca99486b6 100644--- a/backend/plugin/db/mysql/stats_test.go+++ b/backend/plugin/db/mysql/stats_test.go@@ -5,6 +5,7 @@ import ("database/sql""database/sql/driver""io"+ "strings""testing""github.com/stretchr/testify/require"@@ -13,6 +14,10 @@ import (var testOceanBaseExplainRows [][]driver.Valuevar testMySQLExplainRows [][]driver.Value+// testMySQLExplainJSON is returned for `EXPLAIN FORMAT=JSON` queries; when empty, the+// JSON query returns no rows and CountAffectedRows falls back to the tabular rows.+var testMySQLExplainJSON string+func init() {sql.Register("test_oceanbase_explain", testOceanBaseExplainDriver{})sql.Register("test_mysql_explain", testMySQLExplainDriver{})@@ -84,17 +89,28 @@ func (testMySQLExplainConn) Begin() (driver.Tx, error) {return nil, driver.ErrSkip}-func (testMySQLExplainConn) QueryContext(context.Context, string, []driver.NamedValue) (driver.Rows, error) {- return &testMySQLExplainResultRows{rows: testMySQLExplainRows}, nil+func (testMySQLExplainConn) QueryContext(_ context.Context, query string, _ []driver.NamedValue) (driver.Rows, error) {+ if strings.HasPrefix(query, "EXPLAIN FORMAT=JSON") {+ var rows [][]driver.Value+ if testMySQLExplainJSON != "" {+ rows = [][]driver.Value{{testMySQLExplainJSON}}+ }+ return &testMySQLExplainResultRows{columns: []string{"EXPLAIN"}, rows: rows}, nil+ }+ return &testMySQLExplainResultRows{+ columns: []string{"id", "select_type", "table", "type", "rows", "filtered"},+ rows: testMySQLExplainRows,+ }, nil}type testMySQLExplainResultRows struct {- rows [][]driver.Value- idx int+ columns []string+ rows [][]driver.Value+ idx int}-func (*testMySQLExplainResultRows) Columns() []string {- return []string{"id", "select_type", "table", "type", "rows", "filtered"}+func (r *testMySQLExplainResultRows) Columns() []string {+ return r.columns}func (*testMySQLExplainResultRows) Close() error {@@ -111,6 +127,7 @@ func (r *testMySQLExplainResultRows) Next(dest []driver.Value) error {}func TestCountAffectedRowsCapsExplainEstimateByLimit(t *testing.T) {+ testMySQLExplainJSON = ""testMySQLExplainRows = [][]driver.Value{{int64(1), "SIMPLE", "td", "ALL", int64(1000), "100.00"},}@@ -147,6 +164,35 @@ func TestCountAffectedRowsCapsExplainEstimateByLimit(t *testing.T) {}}+func TestCountAffectedRowsPrefersJSONPlanTargetNode(t *testing.T) {+ // The tabular EXPLAIN's first row is a driving-table scan estimate; the JSON plan+ // flags the update target whose cumulative estimate is far smaller (BYT-9858).+ testMySQLExplainJSON = `{"query_block":{"select_id":1,"nested_loop":[+ {"table":{"table_name":"t","access_type":"ALL","rows_examined_per_scan":100232,"rows_produced_per_join":3006,"filtered":"3.00"}},+ {"table":{"update":true,"table_name":"o","access_type":"ref","rows_examined_per_scan":3,"rows_produced_per_join":1144,"filtered":"10.00"}}+ ]}}`+ testMySQLExplainRows = [][]driver.Value{+ {int64(1), "SIMPLE", "t", "ALL", int64(100232), "3.00"},+ {int64(1), "UPDATE", "o", "ref", int64(3), "10.00"},+ }+ defer func() { testMySQLExplainJSON = "" }()++ db, err := sql.Open("test_mysql_explain", "")+ require.NoError(t, err)+ defer db.Close()++ driver := &Driver{db: db}++ got, err := driver.CountAffectedRows(context.Background(), "UPDATE o SET c = 1 WHERE c IS NULL AND EXISTS (SELECT 1 FROM t WHERE t.k = o.k);")+ require.NoError(t, err)+ require.Equal(t, int64(1144), got)++ // The statement LIMIT still caps the JSON-plan estimate.+ got, err = driver.CountAffectedRows(context.Background(), "UPDATE o SET c = 1 WHERE c IS NULL LIMIT 10;")+ require.NoError(t, err)+ require.Equal(t, int64(10), got)+}+func TestCountAffectedRowsForOceanBaseConcatenatesExplainRows(t *testing.T) {testOceanBaseExplainRows = [][]driver.Value{{`{`},diff --git a/backend/plugin/parser/mysql/explain_plan.go b/backend/plugin/parser/mysql/explain_plan.gonew file mode 100644index 0000000000..d35db6059b--- /dev/null+++ b/backend/plugin/parser/mysql/explain_plan.go@@ -0,0 +1,107 @@+package mysql++import (+ "encoding/json"+ "strconv"+)++// GetEstimatedAffectedRowsFromExplainJSON estimates the number of rows affected by an+// UPDATE/DELETE statement from `EXPLAIN FORMAT=JSON` output.+//+// MySQL and MariaDB flag the plan node of each DML target table with "update"/"delete"+// (boolean true on MySQL, integer 1 on MariaDB). Unlike the first "rows" value of the+// tabular EXPLAIN output — which may be the scan estimate of a driving table unrelated+// to the target — the target node carries the optimizer's cardinality estimate for the+// rows actually reaching the modify step. Estimates of multiple target nodes+// (multi-table DELETE/UPDATE) are summed.+//+// The boolean result reports whether any flagged target node with a row estimate was+// found; callers should fall back to the tabular-EXPLAIN heuristic when it is false.+func GetEstimatedAffectedRowsFromExplainJSON(plan string) (int64, bool) {+ var root any+ if err := json.Unmarshal([]byte(plan), &root); err != nil {+ return 0, false+ }+ var total float64+ found := false+ var walk func(node any)+ walk = func(node any) {+ switch n := node.(type) {+ case map[string]any:+ if isDMLTargetNode(n) {+ if estimate, ok := targetNodeRowEstimate(n); ok {+ total += estimate+ found = true+ }+ }+ for _, v := range n {+ walk(v)+ }+ case []any:+ for _, v := range n {+ walk(v)+ }+ default:+ }+ }+ walk(root)+ if !found {+ return 0, false+ }+ return int64(total), true+}++func isDMLTargetNode(node map[string]any) bool {+ for _, key := range []string{"update", "delete"} {+ switch v := node[key].(type) {+ case bool:+ if v {+ return true+ }+ case float64:+ if v != 0 {+ return true+ }+ default:+ }+ }+ return false+}++// targetNodeRowEstimate prefers "rows_produced_per_join", the cumulative cardinality+// after all join and filter conditions up to this node. When absent (single-table+// plans, MariaDB), it scales the per-scan row estimate by the node's "filtered"+// percentage.+func targetNodeRowEstimate(node map[string]any) (float64, bool) {+ if v, ok := toFloat(node["rows_produced_per_join"]); ok {+ return v, true+ }+ base, ok := toFloat(node["rows_examined_per_scan"])+ if !ok {+ // MariaDB names the per-scan estimate "rows".+ base, ok = toFloat(node["rows"])+ }+ if !ok {+ return 0, false+ }+ if filtered, ok := toFloat(node["filtered"]); ok {+ base = base * filtered / 100+ }+ return base, true+}++func toFloat(v any) (float64, bool) {+ switch value := v.(type) {+ case float64:+ return value, true+ case string:+ // MySQL renders "filtered" as a string such as "10.00".+ f, err := strconv.ParseFloat(value, 64)+ if err != nil {+ return 0, false+ }+ return f, true+ default:+ return 0, false+ }+}diff --git a/backend/plugin/parser/mysql/explain_plan_test.go b/backend/plugin/parser/mysql/explain_plan_test.gonew file mode 100644index 0000000000..3447b4bffa--- /dev/null+++ b/backend/plugin/parser/mysql/explain_plan_test.go@@ -0,0 +1,93 @@+package mysql++import (+ "os"+ "path/filepath"+ "testing"++ "github.com/stretchr/testify/require"+)++// The fixtures are real `EXPLAIN FORMAT=JSON` outputs captured from MySQL 8.0 and+// MariaDB 11 against a 400k-row target_table joined with a 100k-row related_table.+func TestGetEstimatedAffectedRowsFromExplainJSON(t *testing.T) {+ for _, tc := range []struct {+ fixture string+ wantRows int64+ wantFound bool+ }{+ {+ // UPDATE ... WHERE ... EXISTS rewritten to a semijoin; the target table is+ // the last nested_loop node. The first tabular EXPLAIN row would report the+ // 100232-row driving-table scan (BYT-9858).+ fixture: "semijoin_update.json",+ wantRows: 1144,+ wantFound: true,+ },+ {+ // Single-table DELETE with a range condition: no rows_produced_per_join,+ // estimate is rows_examined_per_scan scaled by filtered.+ fixture: "single_delete.json",+ wantRows: 200,+ wantFound: true,+ },+ {+ // UPDATE ... ORDER BY ... LIMIT wraps the target node in ordering_operation.+ fixture: "order_limit_update.json",+ wantRows: 200,+ wantFound: true,+ },+ {+ // NOT EXISTS antijoin: the target table is the first nested_loop node.+ fixture: "not_exists_update.json",+ wantRows: 39964,+ wantFound: true,+ },+ {+ // IN (SELECT ...) materialization: the subquery plan lives in+ // attached_subqueries and must not contribute to the estimate.+ fixture: "in_materialized_update.json",+ wantRows: 399648,+ wantFound: true,+ },+ {+ // DELETE o, t FROM ... flags both target nodes; estimates are summed.+ fixture: "multi_target_delete.json",+ wantRows: 48186,+ wantFound: true,+ },+ {+ fixture: "delete_limit.json",+ wantRows: 10,+ wantFound: true,+ },+ {+ // MariaDB marks the target with "update": 1 and names the estimate "rows".+ fixture: "mariadb_update.json",+ wantRows: 10000,+ wantFound: true,+ },+ {+ // SELECT plans have no update/delete node; callers must fall back.+ fixture: "select_only.json",+ wantRows: 0,+ wantFound: false,+ },+ } {+ t.Run(tc.fixture, func(t *testing.T) {+ plan, err := os.ReadFile(filepath.Join("test-data", "explain-plan", tc.fixture))+ require.NoError(t, err)+ rows, found := GetEstimatedAffectedRowsFromExplainJSON(string(plan))+ require.Equal(t, tc.wantFound, found)+ require.Equal(t, tc.wantRows, rows)+ })+ }+}++func TestGetEstimatedAffectedRowsFromExplainJSONInvalidInput(t *testing.T) {+ for _, plan := range []string{"", "not json", "[]", `{"query_block":{}}`} {+ rows, found := GetEstimatedAffectedRowsFromExplainJSON(plan)+ require.False(t, found, plan)+ require.Zero(t, rows, plan)+ }+}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/delete_limit.json b/backend/plugin/parser/mysql/test-data/explain-plan/delete_limit.jsonnew file mode 100644index 0000000000..45778dd2c3--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/delete_limit.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"table":{"delete":true,"table_name":"target_table","access_type":"ALL","rows_examined_per_scan":10,"filtered":"100.00"}}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/in_materialized_update.json b/backend/plugin/parser/mysql/test-data/explain-plan/in_materialized_update.jsonnew file mode 100644index 0000000000..500811841c--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/in_materialized_update.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"cost_info":{"query_cost":"40149.05"},"table":{"update":true,"table_name":"o","access_type":"ALL","rows_examined_per_scan":399648,"rows_produced_per_join":399648,"filtered":"100.00","cost_info":{"read_cost":"184.25","eval_cost":"39964.80","prefix_cost":"40149.05","data_read_per_join":"6M"},"used_columns":["id","join_key","target_flag"],"attached_condition":"<in_optimizer>(`test`.`o`.`join_key`,`test`.`o`.`join_key` in ( <materialize> (/* select#2 */ select `test`.`t`.`join_key` from `test`.`related_table` `t` where (`test`.`t`.`filter_column_1` = 'VALUE_A') group by `test`.`t`.`join_key` having (count(0) > 0) ), <primary_index_lookup>(`test`.`o`.`join_key` in <temporary table> on <auto_distinct_key> where ((`test`.`o`.`join_key` = `<materialized_subquery>`.`join_key`)))))","attached_subqueries":[{"table":{"table_name":"<materialized_subquery>","access_type":"eq_ref","key":"<auto_key>","key_length":"4","rows_examined_per_scan":1,"materialized_from_subquery":{"using_temporary_table":true,"dependent":true,"cacheable":false,"query_block":{"select_id":2,"cost_info":{"query_cost":"10095.45"},"grouping_operation":{"using_filesort":false,"table":{"table_name":"t","access_type":"index","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","rows_examined_per_scan":100232,"rows_produced_per_join":10023,"filtered":"10.00","cost_info":{"read_cost":"9093.13","eval_cost":"1002.32","prefix_cost":"10095.45","data_read_per_join":"1M"},"used_columns":["id","join_key","filter_column_1"],"attached_condition":"(`test`.`t`.`filter_column_1` = 'VALUE_A')"}}}}}}]}}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/mariadb_update.json b/backend/plugin/parser/mysql/test-data/explain-plan/mariadb_update.jsonnew file mode 100644index 0000000000..5302f6f379--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/mariadb_update.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"table":{"update":1,"table_name":"o","access_type":"index","key":"PRIMARY","key_length":"","used_key_parts":["id"],"rows":10000,"attached_condition":"o.target_flag is null and <in_optimizer>(1,exists(subquery#2))"},"subqueries":[{"query_block":{"select_id":2,"cost":0.00345856,"nested_loop":[{"table":{"table_name":"t","access_type":"ref","possible_keys":["idx_join_key"],"key":"idx_join_key","key_length":"4","used_key_parts":["join_key"],"ref":["test.o.join_key"],"loops":1,"rows":1,"cost":0.00345856,"filtered":100,"attached_condition":"t.filter_column_1 = 'VALUE_A'"}}]}}]}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/multi_target_delete.json b/backend/plugin/parser/mysql/test-data/explain-plan/multi_target_delete.jsonnew file mode 100644index 0000000000..b3d47dec4f--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/multi_target_delete.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"cost_info":{"query_cost":"16424.46"},"nested_loop":[{"table":{"delete":true,"table_name":"t","access_type":"ALL","possible_keys":["idx_join_key"],"rows_examined_per_scan":100232,"rows_produced_per_join":10023,"filtered":"10.00","cost_info":{"read_cost":"9093.13","eval_cost":"1002.32","prefix_cost":"10095.45","data_read_per_join":"1M"},"used_columns":["id","join_key","filter_column_1","filter_column_2"],"attached_condition":"(`test`.`t`.`filter_column_1` = 'VALUE_A')"}},{"table":{"delete":true,"table_name":"o","access_type":"ref","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","ref":["test.t.join_key"],"rows_examined_per_scan":3,"rows_produced_per_join":38163,"filtered":"100.00","cost_info":{"read_cost":"2512.66","eval_cost":"3816.35","prefix_cost":"16424.46","data_read_per_join":"596K"},"used_columns":["id","join_key","target_flag"]}}]}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/not_exists_update.json b/backend/plugin/parser/mysql/test-data/explain-plan/not_exists_update.jsonnew file mode 100644index 0000000000..a74913dad7--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/not_exists_update.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"cost_info":{"query_cost":"54299.65"},"nested_loop":[{"table":{"update":true,"table_name":"o","access_type":"ALL","rows_examined_per_scan":399648,"rows_produced_per_join":39964,"filtered":"10.00","cost_info":{"read_cost":"36152.57","eval_cost":"3996.48","prefix_cost":"40149.05","data_read_per_join":"624K"},"used_columns":["id","join_key","target_flag"],"attached_condition":"(`test`.`o`.`target_flag` is null)"}},{"table":{"table_name":"t","access_type":"ref","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","ref":["test.o.join_key"],"rows_examined_per_scan":1,"rows_produced_per_join":39964,"filtered":"100.00","not_exists":true,"cost_info":{"read_cost":"10107.57","eval_cost":"3996.48","prefix_cost":"54299.65","data_read_per_join":"6M"},"used_columns":["join_key","filter_column_1"],"attached_condition":"(<if>(is_not_null_compl(t), (`test`.`t`.`filter_column_1` = 'VALUE_A'), true) and <if>(is_not_null_compl(t), <if>(found_match(t), false, true), true))"}}]}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/order_limit_update.json b/backend/plugin/parser/mysql/test-data/explain-plan/order_limit_update.jsonnew file mode 100644index 0000000000..023b012176--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/order_limit_update.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"ordering_operation":{"using_filesort":true,"table":{"update":true,"table_name":"target_table","access_type":"range","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","ref":["const"],"rows_examined_per_scan":200,"filtered":"100.00","attached_condition":"(`test`.`target_table`.`join_key` < 50)"}}}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/select_only.json b/backend/plugin/parser/mysql/test-data/explain-plan/select_only.jsonnew file mode 100644index 0000000000..69bb7b8ae7--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/select_only.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"cost_info":{"query_cost":"90.26"},"table":{"table_name":"target_table","access_type":"range","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","rows_examined_per_scan":200,"rows_produced_per_join":200,"filtered":"100.00","index_condition":"(`test`.`target_table`.`join_key` < 50)","cost_info":{"read_cost":"70.26","eval_cost":"20.00","prefix_cost":"90.26","data_read_per_join":"3K"},"used_columns":["id","join_key","target_flag"]}}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/semijoin_update.json b/backend/plugin/parser/mysql/test-data/explain-plan/semijoin_update.jsonnew file mode 100644index 0000000000..273c7ad565--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/semijoin_update.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"cost_info":{"query_cost":"14332.59"},"duplicates_removal":{"using_temporary_table":true,"nested_loop":[{"table":{"table_name":"t","access_type":"ALL","possible_keys":["idx_join_key"],"rows_examined_per_scan":100232,"rows_produced_per_join":3006,"filtered":"3.00","cost_info":{"read_cost":"9794.75","eval_cost":"300.70","prefix_cost":"10095.45","data_read_per_join":"516K"},"used_columns":["join_key","filter_column_1","filter_column_2"],"attached_condition":"((`test`.`t`.`filter_column_1` = 'VALUE_A') and (`test`.`t`.`filter_column_2` in ('VALUE_B','VALUE_C','VALUE_D')))"}},{"table":{"update":true,"table_name":"o","access_type":"ref","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","ref":["test.t.join_key"],"rows_examined_per_scan":3,"rows_produced_per_join":1144,"filtered":"10.00","cost_info":{"read_cost":"2862.26","eval_cost":"114.49","prefix_cost":"14332.59","data_read_per_join":"17K"},"used_columns":["id","join_key","target_flag"],"attached_condition":"(`test`.`o`.`target_flag` is null)"}}]}}}diff --git a/backend/plugin/parser/mysql/test-data/explain-plan/single_delete.json b/backend/plugin/parser/mysql/test-data/explain-plan/single_delete.jsonnew file mode 100644index 0000000000..711eb9767a--- /dev/null+++ b/backend/plugin/parser/mysql/test-data/explain-plan/single_delete.json@@ -0,0 +1 @@+{"query_block":{"select_id":1,"table":{"delete":true,"table_name":"target_table","access_type":"range","possible_keys":["idx_join_key"],"key":"idx_join_key","used_key_parts":["join_key"],"key_length":"4","ref":["const"],"rows_examined_per_scan":200,"filtered":"100.00","attached_condition":"(`test`.`target_table`.`join_key` < 50)"}}}