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: admin executing explain analyze returns correct result (#13668)
rebelice656139852442
diff --git a/backend/plugin/parser/mysql/query.go b/backend/plugin/parser/mysql/query.goindex 4393a22e5a..1ceca03321 100644--- a/backend/plugin/parser/mysql/query.go+++ b/backend/plugin/parser/mysql/query.go@@ -34,6 +34,7 @@ func validateQuery(statement string) (bool, bool, error) {return false, false, err}hasExecute := false+ readOnly := truefor _, item := range trees {l := &queryValidateListener{valid: true,@@ -43,18 +44,22 @@ func validateQuery(statement string) (bool, bool, error) {if !l.valid {return false, false, nil}+ if l.explainAnalyze {+ readOnly = false+ }if l.hasExecute {hasExecute = true}}- return true, !hasExecute, nil+ return readOnly, !hasExecute, nil}type queryValidateListener struct {*parser.BaseMySQLParserListener- valid bool- hasExecute bool+ valid bool+ explainAnalyze bool+ hasExecute bool}// EnterQuery is called when production query is entered.@@ -91,7 +96,7 @@ func (l *queryValidateListener) EnterUtilityStatement(ctx *parser.UtilityStateme}if ctx.ExplainStatement() != nil {if ctx.ExplainStatement().ANALYZE_SYMBOL() != nil {- l.valid = false+ l.explainAnalyze = truereturn}}diff --git a/backend/plugin/parser/mysql/query_test.go b/backend/plugin/parser/mysql/query_test.goindex 8473bab67b..6f79e41ee2 100644--- a/backend/plugin/parser/mysql/query_test.go+++ b/backend/plugin/parser/mysql/query_test.go@@ -63,12 +63,12 @@ func TestValidateSQLForEditor(t *testing.T) {{statement: `explain analyze select * from t`,valid: false,- gotAllQuery: false,+ gotAllQuery: true,},{statement: `explain analyze update t set a = 5`,valid: false,- gotAllQuery: false,+ gotAllQuery: true,},{statement: `diff --git a/backend/plugin/parser/tidb/query.go b/backend/plugin/parser/tidb/query.goindex 803d0c276a..84a1f61ff7 100644--- a/backend/plugin/parser/tidb/query.go+++ b/backend/plugin/parser/tidb/query.go@@ -26,6 +26,7 @@ func validateQuery(statement string) (bool, bool, error) {return false, false, err}hasExecute := false+ readOnly := truefor _, stmt := range stmtList {switch stmt := stmt.(type) {case *tidbast.SelectStmt:@@ -34,13 +35,13 @@ func validateQuery(statement string) (bool, bool, error) {case *tidbast.ShowStmt:case *tidbast.ExplainStmt:if stmt.Analyze {- return false, false, nil+ readOnly = false}default:return false, false, nil}}- return true, !hasExecute, nil+ return readOnly, !hasExecute, nil}func ExtractResourceList(currentDatabase string, _, sql string) ([]base.SchemaResource, error) {diff --git a/backend/plugin/parser/tidb/query_test.go b/backend/plugin/parser/tidb/query_test.goindex 9f40e71a0d..5ec2b8f847 100644--- a/backend/plugin/parser/tidb/query_test.go+++ b/backend/plugin/parser/tidb/query_test.go@@ -61,12 +61,12 @@ func TestValidateSQLForEditor(t *testing.T) {{statement: `explain analyze select * from t`,valid: false,- gotAllQuery: false,+ gotAllQuery: true,},{statement: `explain analyze update t set a = 5`,valid: false,- gotAllQuery: false,+ gotAllQuery: true,},{statement: `