Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: update tidb explain result display (#9308)
Danny Xua766a8afd9ba
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.goindex e09d2d8f3d..5656dbaf6b 100644--- a/backend/plugin/db/mysql/mysql.go+++ b/backend/plugin/db/mysql/mysql.go@@ -9,7 +9,6 @@ import ("net""strings""time"- "unicode""github.com/go-sql-driver/mysql""github.com/pkg/errors"@@ -267,36 +266,9 @@ func (driver *Driver) querySingleSQL(ctx context.Context, conn *sql.Conn, single}result.Latency = durationpb.New(time.Since(startTime))result.Statement = statement- if isExplain && driver.dbType == storepb.Engine_TIDB {- if err := updateTiDBExplainResult(result); err != nil {- return nil, err- }- }return result, nil}-func updateTiDBExplainResult(result *v1pb.QueryResult) error {- for _, row := range result.Rows {- if len(row.Values) > 0 {- str := row.Values[0].GetStringValue()- var sb strings.Builder- for i, char := range str {- if unicode.IsLetter(char) {- if _, err := sb.WriteString(str[i:]); err != nil {- return err- }- break- }- if _, err := sb.WriteString("-"); err != nil {- return err- }- }- row.Values[0] = &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: sb.String()}}- }- }- return nil-}-// RunStatement runs a SQL statement in a given connection.func (*Driver) RunStatement(ctx context.Context, conn *sql.Conn, statement string) ([]*v1pb.QueryResult, error) {return util.RunStatement(ctx, storepb.Engine_MYSQL, conn, statement)diff --git a/backend/plugin/db/mysql/mysql_test.go b/backend/plugin/db/mysql/mysql_test.godeleted file mode 100644index f3b88149d9..0000000000--- a/backend/plugin/db/mysql/mysql_test.go+++ /dev/null@@ -1,48 +0,0 @@-package mysql--import (- "testing"-- "github.com/stretchr/testify/require"-- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"-)--func TestUpdateTiDBExplainResult(t *testing.T) {- a := require.New(t)- got := &v1pb.QueryResult{- Rows: []*v1pb.QueryRow{- convertExplainRow("Projection_9", "a"),- convertExplainRow("└─IndexJoin_13", "b"),- convertExplainRow("├─TableReader_26(Build)", "c"),- convertExplainRow("│ └─Selection_25", "d"),- convertExplainRow("│ └─TableFullScan_24", "e"),- convertExplainRow("└─IndexLookUp_12(Probe)", "f"),- convertExplainRow("├─IndexRangeScan_10(Build)", "g"),- convertExplainRow("└─TableRowIDScan_11(Probe)", "h"),- },- }- want := &v1pb.QueryResult{- Rows: []*v1pb.QueryRow{- convertExplainRow("Projection_9", "a"),- convertExplainRow("--IndexJoin_13", "b"),- convertExplainRow("--TableReader_26(Build)", "c"),- convertExplainRow("----Selection_25", "d"),- convertExplainRow("------TableFullScan_24", "e"),- convertExplainRow("--IndexLookUp_12(Probe)", "f"),- convertExplainRow("--IndexRangeScan_10(Build)", "g"),- convertExplainRow("--TableRowIDScan_11(Probe)", "h"),- },- }- err := updateTiDBExplainResult(got)- a.NoError(err)- a.Equal(want, got)-}--func convertExplainRow(values ...string) *v1pb.QueryRow {- row := &v1pb.QueryRow{}- for _, v := range values {- row.Values = append(row.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v}})- }- return row-}