Skip to content

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

fix: classify CALL/EXEC stored procedure statements as DML across all engines (#19563)

p0ny8918940e71ac
diff --git a/backend/plugin/parser/bigquery/query_type.go b/backend/plugin/parser/bigquery/query_type.go
index dcf118ee2d..a208405e9b 100644
--- a/backend/plugin/parser/bigquery/query_type.go
+++ b/backend/plugin/parser/bigquery/query_type.go
@@ -39,7 +39,7 @@ func (l *queryTypeListener) getQueryTypeForUnterminatedSQLStatement(u parser.IUn
body.Create_schema_statement() != nil, body.Create_external_schema_statement() != nil, body.Create_snapshot_statement() != nil, body.Create_table_function_statement() != nil, body.Create_table_statement() != nil,
body.Create_view_statement() != nil, body.Create_entity_statement() != nil, body.Rename_statement() != nil, body.Drop_all_row_access_policies_statement() != nil, body.Drop_statement() != nil, body.Undrop_statement() != nil:
return base.DDL
- case body.Dml_statement() != nil, body.Merge_statement() != nil:
+ case body.Dml_statement() != nil, body.Merge_statement() != nil, body.Call_statement() != nil:
return base.DML
case body.Explain_statement() != nil:
return base.Explain
diff --git a/backend/plugin/parser/doris/query_type.go b/backend/plugin/parser/doris/query_type.go
index 32b45a9bcf..bebba7414d 100644
--- a/backend/plugin/parser/doris/query_type.go
+++ b/backend/plugin/parser/doris/query_type.go
@@ -169,6 +169,11 @@ func (l *queryTypeListener) EnterSupportedOtherStatementAlias(_ *parser.Supporte
l.result = base.DDL
}
+// EnterCallProcedure is called for CALL stored procedure statements.
+func (l *queryTypeListener) EnterCallProcedure(_ *parser.CallProcedureContext) {
+ l.result = base.DML
+}
+
// EnterSupportedStatsStatementAlias is called for stats statements.
func (l *queryTypeListener) EnterSupportedStatsStatementAlias(_ *parser.SupportedStatsStatementAliasContext) {
l.result = base.DDL
diff --git a/backend/plugin/parser/pg/query_type.go b/backend/plugin/parser/pg/query_type.go
index acfd0861f7..b5b5897c89 100644
--- a/backend/plugin/parser/pg/query_type.go
+++ b/backend/plugin/parser/pg/query_type.go
@@ -200,6 +200,11 @@ func (q *queryTypeListener) getStatementType(stmt pgparser.IStmtContext) base.Qu
return base.DML
}
+ // CALL stored procedure is DML
+ if stmt.Callstmt() != nil {
+ return base.DML
+ }
+
// Default to unknown for any unhandled statement types
return base.QueryTypeUnknown
}
diff --git a/backend/plugin/parser/pg/test-data/query_type.yaml b/backend/plugin/parser/pg/test-data/query_type.yaml
index c4feb5e77c..fcbc42db66 100644
--- a/backend/plugin/parser/pg/test-data/query_type.yaml
+++ b/backend/plugin/parser/pg/test-data/query_type.yaml
@@ -559,3 +559,15 @@
results: []
sourcecolumns: []
predicatecolumns: []
+- description: CALL stored procedure
+ statement: CALL my_procedure(1, 'test');
+ defaultDatabase: db
+ metadata: |-
+ {
+ "name": "db"
+ }
+ querySpan:
+ type: 5
+ results: []
+ sourcecolumns: []
+ predicatecolumns: []
diff --git a/backend/plugin/parser/plsql/query_type.go b/backend/plugin/parser/plsql/query_type.go
index e93d7eef91..e800864997 100644
--- a/backend/plugin/parser/plsql/query_type.go
+++ b/backend/plugin/parser/plsql/query_type.go
@@ -149,6 +149,8 @@ func (l *queryTypeListener) EnterUnit_statement(ctx *plsql.Unit_statementContext
return
}
l.result = base.DML
+ case ctx.Sql_call_statement() != nil:
+ l.result = base.DML
default:
// Other statement types
}
diff --git a/backend/plugin/parser/redshift/query_type.go b/backend/plugin/parser/redshift/query_type.go
index e0b6491a78..dc6d31c85f 100644
--- a/backend/plugin/parser/redshift/query_type.go
+++ b/backend/plugin/parser/redshift/query_type.go
@@ -199,6 +199,11 @@ func (q *queryTypeListener) getStatementType(stmt parser.IStmtContext) base.Quer
return base.DML
}
+ // CALL stored procedure is DML
+ if stmt.Callstmt() != nil {
+ return base.DML
+ }
+
// Default to unknown for any unhandled statement types
return base.QueryTypeUnknown
}
diff --git a/backend/plugin/parser/snowflake/query_type.go b/backend/plugin/parser/snowflake/query_type.go
index ca95d67ad1..04927e88b2 100644
--- a/backend/plugin/parser/snowflake/query_type.go
+++ b/backend/plugin/parser/snowflake/query_type.go
@@ -66,6 +66,12 @@ func (*queryTypeListener) getQueryTypeForOtherCommand(otherCommand parser.IOther
return base.DDL, nil
case otherCommand.Set() != nil:
return base.Select, nil
+ case otherCommand.Call() != nil:
+ return base.DML, nil
+ case otherCommand.Execute_immediate() != nil:
+ return base.DML, nil
+ case otherCommand.Execute_task() != nil:
+ return base.DML, nil
default:
return base.QueryTypeUnknown, nil
}
diff --git a/backend/plugin/parser/spanner/query_type.go b/backend/plugin/parser/spanner/query_type.go
index a5478149fc..321a137e06 100644
--- a/backend/plugin/parser/spanner/query_type.go
+++ b/backend/plugin/parser/spanner/query_type.go
@@ -39,7 +39,7 @@ func (l *queryTypeListener) getQueryTypeForUnterminatedSQLStatement(u parser.IUn
body.Create_schema_statement() != nil, body.Create_external_schema_statement() != nil, body.Create_snapshot_statement() != nil, body.Create_table_function_statement() != nil, body.Create_table_statement() != nil,
body.Create_view_statement() != nil, body.Create_entity_statement() != nil, body.Rename_statement() != nil, body.Drop_all_row_access_policies_statement() != nil, body.Drop_statement() != nil, body.Undrop_statement() != nil:
return base.DDL
- case body.Dml_statement() != nil, body.Merge_statement() != nil:
+ case body.Dml_statement() != nil, body.Merge_statement() != nil, body.Call_statement() != nil:
return base.DML
case body.Explain_statement() != nil:
return base.Explain
diff --git a/backend/plugin/parser/trino/query_type.go b/backend/plugin/parser/trino/query_type.go
index 0bad3177e5..9841edab3a 100644
--- a/backend/plugin/parser/trino/query_type.go
+++ b/backend/plugin/parser/trino/query_type.go
@@ -116,6 +116,11 @@ func (l *queryTypeListener) EnterMerge(_ *parser.MergeContext) {
l.result = base.DML
}
+// EnterCall is called when entering a CallContext rule (CALL stored procedure).
+func (l *queryTypeListener) EnterCall(_ *parser.CallContext) {
+ l.result = base.DML
+}
+
// EnterCreateTable is called when entering a CreateTableContext rule.
func (l *queryTypeListener) EnterCreateTable(_ *parser.CreateTableContext) {
l.result = base.DDL
diff --git a/backend/plugin/parser/tsql/query_type.go b/backend/plugin/parser/tsql/query_type.go
index 06021ba3a9..f7380cd43f 100644
--- a/backend/plugin/parser/tsql/query_type.go
+++ b/backend/plugin/parser/tsql/query_type.go
@@ -64,6 +64,10 @@ func (l *queryTypeListener) getQueryTypeForSQLClause(clause parser.ISql_clausesC
if clause.Another_statement().Set_statement() != nil || clause.Another_statement().Setuser_statement() != nil || clause.Another_statement().Declare_statement() != nil {
return base.Select, nil
}
+ // EXECUTE stored procedure is DML.
+ if clause.Another_statement().Execute_statement() != nil {
+ return base.DML, nil
+ }
return base.QueryTypeUnknown, nil
case clause.Cfl_statement() != nil, clause.Dbcc_clause() != nil, clause.Backup_statement() != nil:
return base.QueryTypeUnknown, nil
@@ -77,6 +81,6 @@ func (*queryTypeListener) getQueryTypeForBatchLevelStatement(parser.IBatch_level
}
func (*queryTypeListener) getQueryTypeForExecuteBodyBatch(parser.IExecute_body_batchContext) (base.QueryType, error) {
- // Call stored procedure or function. Do not detect the type for now.
- return base.QueryTypeUnknown, nil
+ // Call stored procedure or function.
+ return base.DML, nil
}