From 2ef95a65412d9ff866094c0b56904c894734b1c5 Mon Sep 17 00:00:00 2001 From: TCeason <33082201+TCeason@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:27:13 +0800 Subject: [PATCH] fix(query): forbid explain explain statement (#16654) fix(query): forbiden explain explain statement --- src/query/sql/src/planner/binder/binder.rs | 3 +++ src/query/sql/src/planner/binder/explain.rs | 3 +++ .../suites/mode/standalone/explain/explain.test | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/query/sql/src/planner/binder/binder.rs b/src/query/sql/src/planner/binder/binder.rs index 628f49639094..b5eea5af972a 100644 --- a/src/query/sql/src/planner/binder/binder.rs +++ b/src/query/sql/src/planner/binder/binder.rs @@ -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) } } diff --git a/src/query/sql/src/planner/binder/explain.rs b/src/query/sql/src/planner/binder/explain.rs index 7f67e837dc35..640f4f6857c4 100644 --- a/src/query/sql/src/planner/binder/explain.rs +++ b/src/query/sql/src/planner/binder/explain.rs @@ -76,6 +76,9 @@ impl Binder { inner: &Statement, ) -> Result { 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) { diff --git a/tests/sqllogictests/suites/mode/standalone/explain/explain.test b/tests/sqllogictests/suites/mode/standalone/explain/explain.test index 36fbdfdeb958..6dc1cbed25ef 100644 --- a/tests/sqllogictests/suites/mode/standalone/explain/explain.test +++ b/tests/sqllogictests/suites/mode/standalone/explain/explain.test @@ -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 ----