Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): forbid explain explain statement #16654

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading