Skip to content

Commit

Permalink
fix(query): forbid explain explain statement (#16654)
Browse files Browse the repository at this point in the history
fix(query): forbiden explain explain statement
  • Loading branch information
TCeason authored Oct 23, 2024
1 parent 4b8b96e commit 2ef95a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/query/sql/src/planner/binder/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ impl<'a> Binder {
}

Statement::ExplainAnalyze {partial, graphical, query } => {
if let Statement::Explain { .. } | Statement::ExplainAnalyze { .. } = query.as_ref() {
return Err(ErrorCode::SyntaxException("Invalid statement"));
}
let plan = self.bind_statement(bind_context, query).await?;
Plan::ExplainAnalyze { partial: *partial, graphical: *graphical, plan: Box::new(plan) }
}
Expand Down
3 changes: 3 additions & 0 deletions src/query/sql/src/planner/binder/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ impl Binder {
inner: &Statement,
) -> Result<Plan> {
let mut builder = ExplainConfigBuilder::new();
if let Statement::Explain { .. } | Statement::ExplainAnalyze { .. } = inner {
return Err(ErrorCode::SyntaxException("Invalid statement"));
}

// Rewrite `EXPLAIN RAW` to `EXPLAIN(LOGICAL)`
if matches!(kind, ExplainKind::Raw) {
Expand Down
12 changes: 12 additions & 0 deletions tests/sqllogictests/suites/mode/standalone/explain/explain.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ create table t1 as select number as a, number as b from numbers(1)
statement ok
create table t2 as select number as a, number as b from numbers(5)

statement error 1005
explain explain select t1.a from t1 where a > 0

statement error 1005
explain explain analyze select t1.a from t1 where a > 0

statement error 1005
explain analyze explain select t1.a from t1 where a > 0

statement error 1005
explain analyze explain analyze select t1.a from t1 where a > 0

query T
explain select t1.a from t1 where a > 0
----
Expand Down

0 comments on commit 2ef95a6

Please sign in to comment.