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

adapter: remove QGM code #17139

Merged
merged 6 commits into from Jan 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/test/slt-fast.sh
Expand Up @@ -17,7 +17,6 @@ tests=(
test/sqllogictest/*.slt
test/sqllogictest/attributes/*.slt \
test/sqllogictest/explain/*.slt
test/sqllogictest/qgm/*.slt
test/sqllogictest/autogenerated/*.slt
test/sqllogictest/transform/*.slt
# test/sqllogictest/sqlite/test/evidence/in1.test
Expand Down
23 changes: 0 additions & 23 deletions doc/developer/101-query-compilation.md
Expand Up @@ -85,29 +85,6 @@ Existing "fast paths" include:

Currently, the optimization team is mostly concerned with the `HIR ⇒ MIR` and `MIR ⇒ MIR` stages.

<!--
# Future Pipeline

[Diagram](https://docs.google.com/drawings/d/1Fil1-oYy3PkP3bD7WoZphW319Pj60cMAs2HcS9A21uo/edit)

[Design doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/20210707_qgm_sql_high_level_representation.md)

* [`SQL ⇒ AST`](https://github.com/MaterializeInc/materialize/blob/main/src/sql-parser).
* Parsing the SQL query
* `AST ⇒ QGM`.
* Name resolution.
* `QGM ⇒ QGM`.
* Optimizing rewrites + decorrelation + more optimizing rewrites.
* `QGM ⇒ MIR`.
* Lowering.
* [`MIR ⇒ MIR`](https://github.com/MaterializeInc/materialize/blob/main/src/transform).
* Optimizations. What this looks like is to be determined.
* Some optimizations may become redundant after optimizing rewrites are added.
* Note that we may be able to eliminate the per-view/cross-view distinction by modifying MIR to have more than one starting point.
* `MIR ⇒ LIR`.
* `LIR ⇒ TDO`.
-->

## Testing

### Integration tests
Expand Down
73 changes: 10 additions & 63 deletions src/adapter/src/coord/sequencer.rs
Expand Up @@ -2677,23 +2677,19 @@ 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(|| {
trace_plan(&raw_plan);
});

// run optimization pipeline
let decorrelated_plan = raw_plan.optimize_and_lower(&OptimizerConfig {
qgm_optimizations: session.vars().qgm_optimizations(),
})?;
let decorrelated_plan = raw_plan.optimize_and_lower(&OptimizerConfig {})?;

self.validate_timeline_context(decorrelated_plan.depends_on())?;

Expand Down Expand Up @@ -2739,63 +2735,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 Expand Up @@ -2904,9 +2853,7 @@ impl Coordinator {
raw_plan, format, ..
} = plan;

let decorrelated_plan = raw_plan.optimize_and_lower(&OptimizerConfig {
qgm_optimizations: session.vars().qgm_optimizations(),
})?;
let decorrelated_plan = raw_plan.optimize_and_lower(&OptimizerConfig {})?;
let optimized_plan = self.view_optimizer.optimize(decorrelated_plan)?;
let source_ids = optimized_plan.depends_on();
let compute_instance = self.catalog.active_compute_instance(session)?;
Expand Down
10 changes: 0 additions & 10 deletions src/adapter/src/error.rs
Expand Up @@ -22,7 +22,6 @@ use mz_ore::str::StrExt;
use mz_repr::explain_new::ExplainError;
use mz_repr::NotNullViolation;
use mz_sql::plan::PlanError;
use mz_sql::query_model::QGMError;
use mz_storage_client::controller::StorageError;
use mz_transform::TransformError;

Expand Down Expand Up @@ -109,8 +108,6 @@ pub enum AdapterError {
PlanError(PlanError),
/// The named prepared statement already exists.
PreparedStatementExists(String),
/// An error occurred in the QGM stage of the optimizer.
QGM(QGMError),
/// The transaction is in read-only mode.
ReadOnlyTransaction,
/// The specified session parameter is read-only.
Expand Down Expand Up @@ -401,7 +398,6 @@ impl fmt::Display for AdapterError {
AdapterError::PreparedStatementExists(name) => {
write!(f, "prepared statement {} already exists", name.quoted())
}
AdapterError::QGM(e) => e.fmt(f),
AdapterError::ReadOnlyTransaction => f.write_str("transaction in read-only mode"),
AdapterError::ReadOnlyParameter(p) => {
write!(f, "parameter {} cannot be changed", p.name().quoted())
Expand Down Expand Up @@ -552,12 +548,6 @@ impl From<PlanError> for AdapterError {
}
}

impl From<QGMError> for AdapterError {
fn from(e: QGMError) -> AdapterError {
AdapterError::QGM(e)
}
}

impl From<TransformError> for AdapterError {
fn from(e: TransformError) -> AdapterError {
AdapterError::Transform(e)
Expand Down
1 change: 0 additions & 1 deletion src/adapter/src/explain_new/mod.rs
Expand Up @@ -33,7 +33,6 @@ pub(crate) mod hir;
pub(crate) mod lir;
pub(crate) mod mir;
pub(crate) mod optimizer_trace;
pub(crate) mod qgm;

/// Newtype struct for wrapping types that should
/// implement the [`mz_repr::explain_new::Explain`] trait.
Expand Down
46 changes: 0 additions & 46 deletions src/adapter/src/explain_new/qgm/dot.rs

This file was deleted.

37 changes: 0 additions & 37 deletions src/adapter/src/explain_new/qgm/mod.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/adapter/src/session.rs
Expand Up @@ -190,7 +190,7 @@ impl<T: TimestampManipulation> Session<T> {
let id = self.next_transaction_id;
self.next_transaction_id = self.next_transaction_id.wrapping_add(1);
self.transaction = TransactionStatus::InTransaction(Transaction {
pcx: PlanContext::new(wall_time, self.vars.qgm_optimizations()),
pcx: PlanContext::new(wall_time),
ops: TransactionOps::None,
write_lock_guard: None,
access,
Expand Down Expand Up @@ -224,7 +224,7 @@ impl<T: TimestampManipulation> Session<T> {
let id = self.next_transaction_id;
self.next_transaction_id = self.next_transaction_id.wrapping_add(1);
let txn = Transaction {
pcx: PlanContext::new(wall_time, self.vars.qgm_optimizations()),
pcx: PlanContext::new(wall_time),
ops: TransactionOps::None,
write_lock_guard: None,
access: None,
Expand Down
25 changes: 1 addition & 24 deletions src/adapter/src/session/vars.rs
Expand Up @@ -129,13 +129,6 @@ const INTERVAL_STYLE: ServerVar<str> = ServerVar {

const MZ_VERSION_NAME: &UncasedStr = UncasedStr::new("mz_version");

const QGM_OPTIMIZATIONS: ServerVar<bool> = ServerVar {
name: UncasedStr::new("qgm_optimizations_experimental"),
value: &false,
description: "Enables optimizations based on a Query Graph Model (QGM) query representation.",
internal: false,
};

static DEFAULT_SEARCH_PATH: Lazy<[String; 1]> = Lazy::new(|| [DEFAULT_SCHEMA.to_owned()]);
static SEARCH_PATH: Lazy<ServerVar<[String]>> = Lazy::new(|| ServerVar {
name: UncasedStr::new("search_path"),
Expand Down Expand Up @@ -424,7 +417,6 @@ pub struct SessionVars {
failpoints: ServerVar<str>,
integer_datetimes: ServerVar<bool>,
interval_style: ServerVar<str>,
qgm_optimizations: SessionVar<bool>,
search_path: SessionVar<[String]>,
server_version: ServerVar<str>,
server_version_num: ServerVar<i32>,
Expand Down Expand Up @@ -455,7 +447,6 @@ impl SessionVars {
failpoints: FAILPOINTS,
integer_datetimes: INTEGER_DATETIMES,
interval_style: INTERVAL_STYLE,
qgm_optimizations: SessionVar::new(&QGM_OPTIMIZATIONS),
search_path: SessionVar::new(&SEARCH_PATH),
server_version: SERVER_VERSION,
server_version_num: SERVER_VERSION_NUM,
Expand Down Expand Up @@ -483,7 +474,7 @@ impl SessionVars {
/// Returns an iterator over the configuration parameters and their current
/// values for this session.
pub fn iter(&self) -> impl Iterator<Item = &dyn Var> {
let vars: [&dyn Var; 25] = [
let vars: [&dyn Var; 24] = [
&self.application_name,
self.build_info,
&self.client_encoding,
Expand All @@ -496,7 +487,6 @@ impl SessionVars {
&self.failpoints,
&self.integer_datetimes,
&self.interval_style,
&self.qgm_optimizations,
&self.search_path,
&self.server_version,
&self.server_version_num,
Expand Down Expand Up @@ -572,8 +562,6 @@ impl SessionVars {
Ok(&self.interval_style)
} else if name == MZ_VERSION_NAME {
Ok(self.build_info)
} else if name == QGM_OPTIMIZATIONS.name {
Ok(&self.qgm_optimizations)
} else if name == SEARCH_PATH.name {
Ok(&self.search_path)
} else if name == SERVER_VERSION.name {
Expand Down Expand Up @@ -690,8 +678,6 @@ impl SessionVars {
} else {
Ok(())
}
} else if name == QGM_OPTIMIZATIONS.name {
self.qgm_optimizations.set(value, local)
} else if name == SEARCH_PATH.name {
self.search_path.set(value, local)
} else if name == SERVER_VERSION.name {
Expand Down Expand Up @@ -768,8 +754,6 @@ impl SessionVars {
self.database.reset(local);
} else if name == EXTRA_FLOAT_DIGITS.name {
self.extra_float_digits.reset(local);
} else if name == QGM_OPTIMIZATIONS.name {
self.qgm_optimizations.reset(local);
} else if name == SEARCH_PATH.name {
self.search_path.reset(local);
} else if name == SQL_SAFE_UPDATES.name {
Expand Down Expand Up @@ -822,7 +806,6 @@ impl SessionVars {
failpoints: _,
integer_datetimes: _,
interval_style: _,
qgm_optimizations,
search_path,
server_version: _,
server_version_num: _,
Expand All @@ -842,7 +825,6 @@ impl SessionVars {
cluster_replica.end_transaction(action);
database.end_transaction(action);
extra_float_digits.end_transaction(action);
qgm_optimizations.end_transaction(action);
search_path.end_transaction(action);
sql_safe_updates.end_transaction(action);
statement_timeout.end_transaction(action);
Expand Down Expand Up @@ -914,11 +896,6 @@ impl SessionVars {
self.build_info.value()
}

/// Returns the value of the `qgm_optimizations` configuration parameter.
pub fn qgm_optimizations(&self) -> bool {
*self.qgm_optimizations.value()
}

/// Returns the value of the `search_path` configuration parameter.
pub fn search_path(&self) -> Vec<&str> {
self.search_path
Expand Down