Skip to content

Commit

Permalink
sql: remove ExplainStage::(Optimized)QueryGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexandrov committed Jan 13, 2023
1 parent de8a061 commit 4cc0987
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 84 deletions.
65 changes: 8 additions & 57 deletions src/adapter/src/coord/sequencer.rs
Expand Up @@ -2567,13 +2567,11 @@ impl Coordinator {

let optimizer_trace = match stage {
Trace => OptimizerTrace::new(), // collect all trace entries
QueryGraph | OptimizedQueryGraph => OptimizerTrace::find(""), // don't collect anything
stage => OptimizerTrace::find(stage.path()), // collect a trace entry only the selected stage
};

let (used_indexes, fast_path_plan) =
optimizer_trace.collect_trace(|| -> Result<_, AdapterError> {
let raw_plan = raw_plan.clone(); // FIXME: remove `.clone()` once the QGM Model implements Clone.
let _span = tracing::span!(Level::INFO, "optimize").entered();

tracing::span!(Level::INFO, "raw").in_scope(|| {
Expand Down Expand Up @@ -2627,63 +2625,16 @@ impl Coordinator {
Ok((used_indexes, fast_path_plan))
})?;

let trace = if matches!(stage, QueryGraph | OptimizedQueryGraph) {
vec![] // FIXME: remove this case once the QGM Model implements Clone
} else {
optimizer_trace.drain_all(
format.clone(), // FIXME: remove `.clone()` once the QGM Model implements Clone
config.clone(), // FIXME: remove `.clone()` once the QGM Model implements Clone
self.catalog.for_session(session),
row_set_finishing.clone(), // FIXME: remove `.clone()` once the QGM Model implements Clone
used_indexes,
fast_path_plan,
)?
};
let trace = optimizer_trace.drain_all(
format,
config,
self.catalog.for_session(session),
row_set_finishing,
used_indexes,
fast_path_plan,
)?;

let rows = match stage {
// QGM graphs are not collected in the trace at the moment as they
// do not implement Clone (see the TODOs in try_qgm_path.
// Once this is done the next two cases will be handled by the catch-all
// case at the end of this method.
QueryGraph => {
use mz_repr::explain_new::Explain;
// run partial pipeline
let mut model = mz_sql::query_model::Model::try_from(raw_plan)?;
// construct explanation context
let catalog = self.catalog.for_session(session);
let context = crate::explain_new::ExplainContext {
config: &config,
humanizer: &catalog,
used_indexes: crate::explain_new::UsedIndexes::new(Default::default()),
finishing: row_set_finishing,
fast_path_plan: Default::default(),
};
// explain plan
let mut explainable = crate::explain_new::Explainable::new(&mut model);
let explanation_string = explainable.explain(&format, &config, &context)?;
// pack rows in result vector
vec![Row::pack_slice(&[Datum::from(&*explanation_string)])]
}
OptimizedQueryGraph => {
use mz_repr::explain_new::Explain;
// run partial pipeline
let mut model = mz_sql::query_model::Model::try_from(raw_plan)?;
model.optimize();
// construct explanation context
let catalog = self.catalog.for_session(session);
let context = crate::explain_new::ExplainContext {
config: &config,
humanizer: &catalog,
used_indexes: crate::explain_new::UsedIndexes::new(Default::default()),
finishing: row_set_finishing,
fast_path_plan: Default::default(),
};
// explain plan
let mut explainable = crate::explain_new::Explainable::new(&mut model);
let explanation_string = explainable.explain(&format, &config, &context)?;
// pack rows in result vector
vec![Row::pack_slice(&[Datum::from(&*explanation_string)])]
}
// For the `Trace` stage, return the entire trace as (time, path, plan) triples.
Trace => {
let rows = trace
Expand Down
8 changes: 0 additions & 8 deletions src/sql-parser/src/ast/defs/statement.rs
Expand Up @@ -2387,10 +2387,6 @@ impl_display_t!(Assignment);
pub enum ExplainStage {
/// The mz_sql::HirRelationExpr after parsing
RawPlan,
/// Query Graph
QueryGraph,
/// Optimized Query Graph
OptimizedQueryGraph,
/// The mz_expr::MirRelationExpr after decorrelation
DecorrelatedPlan,
/// The mz_expr::MirRelationExpr after optimization
Expand All @@ -2408,8 +2404,6 @@ impl ExplainStage {
pub fn path(&self) -> &'static str {
match self {
ExplainStage::RawPlan => "optimize/raw",
ExplainStage::QueryGraph => "optimize/qgm/raw",
ExplainStage::OptimizedQueryGraph => "optimize/qgm/optimized",
ExplainStage::DecorrelatedPlan => "optimize/hir_to_mir",
ExplainStage::OptimizedPlan => "optimize/global",
ExplainStage::PhysicalPlan => "optimize/mir_to_lir",
Expand All @@ -2423,8 +2417,6 @@ impl AstDisplay for ExplainStage {
fn fmt<W: fmt::Write>(&self, f: &mut AstFormatter<W>) {
match self {
ExplainStage::RawPlan => f.write_str("RAW PLAN"),
ExplainStage::OptimizedQueryGraph => f.write_str("OPTIMIZED QUERY GRAPH"),
ExplainStage::QueryGraph => f.write_str("QUERY GRAPH"),
ExplainStage::DecorrelatedPlan => f.write_str("DECORRELATED PLAN"),
ExplainStage::OptimizedPlan => f.write_str("OPTIMIZED PLAN"),
ExplainStage::PhysicalPlan => f.write_str("PHYSICAL PLAN"),
Expand Down
13 changes: 2 additions & 11 deletions src/sql-parser/src/parser.rs
Expand Up @@ -5545,22 +5545,13 @@ impl<'a> Parser<'a> {
self.expect_keyword(PLAN)?;
Some(ExplainStage::RawPlan)
}
Some(QUERY) => {
self.expect_keyword(GRAPH)?;
Some(ExplainStage::QueryGraph)
}
Some(DECORRELATED) => {
self.expect_keyword(PLAN)?;
Some(ExplainStage::DecorrelatedPlan)
}
Some(OPTIMIZED) => {
if self.parse_keyword(QUERY) {
self.expect_keyword(GRAPH)?;
Some(ExplainStage::OptimizedQueryGraph)
} else {
self.expect_keyword(PLAN)?;
Some(ExplainStage::OptimizedPlan)
}
self.expect_keyword(PLAN)?;
Some(ExplainStage::OptimizedPlan)
}
Some(PLAN) => Some(ExplainStage::OptimizedPlan), // EXPLAIN PLAN ~= EXPLAIN OPTIMIZED PLAN
Some(PHYSICAL) => {
Expand Down
8 changes: 0 additions & 8 deletions src/sql/src/plan/statement/dml.rs
Expand Up @@ -195,14 +195,6 @@ pub fn describe_explain(
relation_desc =
relation_desc.with_column("Raw Plan", ScalarType::String.nullable(false));
}
ExplainStage::QueryGraph => {
relation_desc =
relation_desc.with_column("Query Graph", ScalarType::String.nullable(false));
}
ExplainStage::OptimizedQueryGraph => {
relation_desc = relation_desc
.with_column("Optimized Query Graph", ScalarType::String.nullable(false));
}
ExplainStage::DecorrelatedPlan => {
relation_desc =
relation_desc.with_column("Decorrelated Plan", ScalarType::String.nullable(false));
Expand Down

0 comments on commit 4cc0987

Please sign in to comment.