Skip to content

Commit

Permalink
Merge pull request #7401 from leiysky/explain-physical-plan
Browse files Browse the repository at this point in the history
chore(planner): Add statistics info in explain result
  • Loading branch information
BohuTANG authored Aug 30, 2022
2 parents 8855696 + 1853224 commit ecdd853
Show file tree
Hide file tree
Showing 19 changed files with 1,620 additions and 959 deletions.
4 changes: 2 additions & 2 deletions src/query/ast/src/ast/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub use syntax::pretty_statement;

#[derive(Clone)]
pub struct FormatTreeNode<T: Display + Clone> {
payload: T,
children: Vec<Self>,
pub payload: T,
pub children: Vec<Self>,
}

impl<T> FormatTreeNode<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ impl PhysicalPlanReplacer for ReplaceReadSource {
Ok(PhysicalPlan::TableScan(TableScan {
source: Box::new(self.source.clone()),
name_mapping: plan.name_mapping.clone(),
table_index: plan.table_index,
}))
}
}
28 changes: 26 additions & 2 deletions src/query/service/src/interpreters/interpreter_explain_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use super::fragments::Fragmenter;
use super::QueryFragmentsActions;
use crate::interpreters::Interpreter;
use crate::sessions::QueryContext;
use crate::sql::executor::PhysicalPlan;
use crate::sql::executor::PhysicalPlanBuilder;
use crate::sql::executor::PipelineBuilder;
use crate::sql::optimizer::SExpr;
Expand Down Expand Up @@ -53,7 +54,17 @@ impl Interpreter for ExplainInterpreterV2 {
ExplainKind::Ast(stmt) | ExplainKind::Syntax(stmt) => {
self.explain_ast_or_syntax(stmt.clone())?
}
ExplainKind::Raw | ExplainKind::Plan => self.explain_raw_or_plan(&self.plan)?,
ExplainKind::Raw => self.explain_plan(&self.plan)?,
ExplainKind::Plan => match &self.plan {
Plan::Query {
s_expr, metadata, ..
} => {
let builder = PhysicalPlanBuilder::new(metadata.clone(), self.ctx.clone());
let plan = builder.build(s_expr).await?;
self.explain_physical_plan(&plan, metadata)?
}
_ => self.explain_plan(&self.plan)?,
},
ExplainKind::Pipeline => match &self.plan {
Plan::Query {
s_expr, metadata, ..
Expand Down Expand Up @@ -116,7 +127,7 @@ impl ExplainInterpreterV2 {
])])
}

pub fn explain_raw_or_plan(&self, plan: &Plan) -> Result<Vec<DataBlock>> {
pub fn explain_plan(&self, plan: &Plan) -> Result<Vec<DataBlock>> {
let result = plan.format_indent()?;
let line_splitted_result: Vec<&str> = result.lines().collect();
let formatted_plan = Series::from_data(line_splitted_result);
Expand All @@ -125,6 +136,19 @@ impl ExplainInterpreterV2 {
])])
}

pub fn explain_physical_plan(
&self,
plan: &PhysicalPlan,
metadata: &MetadataRef,
) -> Result<Vec<DataBlock>> {
let result = plan.format(metadata.clone())?;
let line_splitted_result: Vec<&str> = result.lines().collect();
let formatted_plan = Series::from_data(line_splitted_result);
Ok(vec![DataBlock::create(self.schema.clone(), vec![
formatted_plan,
])])
}

pub async fn explain_pipeline(
&self,
s_expr: SExpr,
Expand Down
Loading

1 comment on commit ecdd853

@vercel
Copy link

@vercel vercel bot commented on ecdd853 Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend.rs
databend-git-main-databend.vercel.app
databend.vercel.app

Please sign in to comment.