Skip to content

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

fix: recognize wrapper nodes in the EXPLAIN read-only validation

rebelice0001a4b6d5ce
diff --git a/backend/plugin/parser/doris/query.go b/backend/plugin/parser/doris/query.go
index 2cc0a94565..83b69a4b24 100644
--- a/backend/plugin/parser/doris/query.go
+++ b/backend/plugin/parser/doris/query.go
@@ -94,9 +94,13 @@ func isReadOnlyAST(node ast.Node) bool {
// legitimately wrap (SELECT family or DML). DDL inside EXPLAIN is rejected:
// Doris only supports EXPLAIN on query and DML statements.
func isExplainableInner(node ast.Node) bool {
- switch node.(type) {
+ switch n := node.(type) {
case *ast.SelectStmt, *ast.SetOpStmt:
return true
+ case *ast.GroupedQuery:
+ // EXPLAIN (SELECT 1 LIMIT 1) LIMIT 2 — engine-verified accept;
+ // classify by the wrapped query.
+ return isExplainableInner(n.Query)
case *ast.InsertStmt, *ast.UpdateStmt, *ast.DeleteStmt,
*ast.MergeStmt, *ast.TruncateTableStmt:
return true
diff --git a/backend/plugin/parser/doris/query_test.go b/backend/plugin/parser/doris/query_test.go
index e5735eeff0..86aff1ab9e 100644
--- a/backend/plugin/parser/doris/query_test.go
+++ b/backend/plugin/parser/doris/query_test.go
@@ -196,6 +196,16 @@ func TestValidateQuery(t *testing.T) {
valid: true,
description: "Set operation with parenthesized operand and trailing LIMIT is read-only",
},
+ {
+ statement: "EXPLAIN (SELECT 1)",
+ valid: true,
+ description: "EXPLAIN over a parenthesized query is read-only",
+ },
+ {
+ statement: "EXPLAIN (SELECT 1 LIMIT 1) LIMIT 2",
+ valid: true,
+ description: "EXPLAIN over a grouped query is read-only",
+ },
}
for _, tc := range tests {
diff --git a/backend/plugin/parser/starrocks/query.go b/backend/plugin/parser/starrocks/query.go
index c7149b6026..c372697142 100644
--- a/backend/plugin/parser/starrocks/query.go
+++ b/backend/plugin/parser/starrocks/query.go
@@ -88,9 +88,13 @@ func isReadOnlyAST(node ast.Node) bool {
// legitimately wrap (SELECT family or DML). DDL inside EXPLAIN is rejected:
// Doris only supports EXPLAIN on query and DML statements.
func isExplainableInner(node ast.Node) bool {
- switch node.(type) {
+ switch n := node.(type) {
case *ast.SelectStmt, *ast.SetOpStmt:
return true
+ case *ast.ParenSelect:
+ // EXPLAIN (SELECT ...) / EXPLAIN ((SELECT ...)) — engine-verified
+ // accepts; classify by the wrapped query.
+ return isExplainableInner(n.Sel)
case *ast.InsertStmt, *ast.UpdateStmt, *ast.DeleteStmt,
*ast.MergeStmt, *ast.TruncateTableStmt:
return true
diff --git a/backend/plugin/parser/starrocks/query_test.go b/backend/plugin/parser/starrocks/query_test.go
index 9ea59f649d..7ae808ccfe 100644
--- a/backend/plugin/parser/starrocks/query_test.go
+++ b/backend/plugin/parser/starrocks/query_test.go
@@ -132,6 +132,16 @@ func TestValidateQuery(t *testing.T) {
valid: false,
description: "INTO OUTFILE inside nested parens must not slip the export gate",
},
+ {
+ statement: "EXPLAIN (SELECT 1)",
+ valid: true,
+ description: "EXPLAIN over a parenthesized query is read-only",
+ },
+ {
+ statement: "EXPLAIN ((SELECT 1))",
+ valid: true,
+ description: "EXPLAIN over nested parens is read-only",
+ },
{
statement: "SELECT EXTRACT(YEAR FROM MONTHS_ADD(NOW(), -1))",
valid: true,