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

Printer for the plan, ie: EXPLAIN #2075

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ enum-as-inner = "0.6"
enum-map = "2.6.3"
env_logger = "0.10"
ethnum = { version = "1.5.0", features = ["serde"] }
expect-test = "1.5.0"
flate2 = "1.0.24"
fs-err = "2.9.0"
fs2 = "0.4.3"
Expand Down
6 changes: 4 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spacetimedb-lib = { workspace = true, features = ["serde", "metrics_impls"] }
spacetimedb-client-api-messages.workspace = true
spacetimedb-commitlog.workspace = true
spacetimedb-durability.workspace = true
spacetimedb-expr.workspace = true
spacetimedb-execution.workspace = true
spacetimedb-metrics.workspace = true
spacetimedb-primitives.workspace = true
spacetimedb-paths.workspace = true
Expand All @@ -30,8 +32,6 @@ spacetimedb-schema.workspace = true
spacetimedb-table.workspace = true
spacetimedb-vm.workspace = true
spacetimedb-snapshot.workspace = true
spacetimedb-expr.workspace = true
spacetimedb-execution.workspace = true

anyhow = { workspace = true, features = ["backtrace"] }
arrayvec.workspace = true
Expand All @@ -50,6 +50,7 @@ derive_more.workspace = true
dirs.workspace = true
enum-as-inner.workspace = true
enum-map.workspace = true
expect-test.workspace = true
flate2.workspace = true
fs2.workspace = true
futures.workspace = true
Expand Down Expand Up @@ -119,6 +120,7 @@ default = ["unindexed_iter_by_col_range_warn"]
# Enable test helpers and utils
test = []


[dev-dependencies]
spacetimedb-lib = { path = "../lib", features = ["proptest"] }
spacetimedb-sats = { path = "../sats", features = ["proptest"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/expr/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ pub fn type_subscription(ast: SqlSelect, tx: &impl SchemaView) -> TypingResult<P

/// Parse and type check a *subscription* query into a `StatementCtx`
pub fn compile_sql_sub<'a>(sql: &'a str, tx: &impl SchemaView) -> TypingResult<StatementCtx<'a>> {
let planning_time = std::time::Instant::now();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make planning time external? So that we don't compute it during normal execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So create a wrapper? Because the alternative is to parse EXPLAIN

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just want to make sure we have the option not to time if we're not invoking the printer.

Ok(StatementCtx {
statement: Statement::Select(ProjectList::Name(parse_and_type_sub(sql, tx)?)),
sql,
source: StatementSource::Subscription,
planning_time: planning_time.elapsed(),
})
}

Expand Down
2 changes: 2 additions & 0 deletions crates/expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub(crate) fn parse(value: String, ty: &AlgebraicType) -> Result<AlgebraicValue,
}

/// The source of a statement
#[derive(Debug, Clone, Copy)]
pub enum StatementSource {
Subscription,
Query,
Expand All @@ -187,4 +188,5 @@ pub struct StatementCtx<'a> {
pub statement: Statement,
pub sql: &'a str,
pub source: StatementSource,
pub planning_time: std::time::Duration,
}
2 changes: 2 additions & 0 deletions crates/expr/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,13 @@ fn parse_and_type_sql(sql: &str, tx: &impl SchemaView) -> TypingResult<Statement

/// Parse and type check a *general* query into a [StatementCtx].
pub fn compile_sql_stmt<'a>(sql: &'a str, tx: &impl SchemaView) -> TypingResult<StatementCtx<'a>> {
let planning_time = std::time::Instant::now();
let statement = parse_and_type_sql(sql, tx)?;
Ok(StatementCtx {
statement,
sql,
source: StatementSource::Query,
planning_time: planning_time.elapsed(),
})
}

Expand Down
2 changes: 2 additions & 0 deletions crates/physical-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ description = "The physical query plan for the SpacetimeDB query engine"
[dependencies]
anyhow.workspace = true
derive_more.workspace = true
expect-test.workspace = true
itertools.workspace = true
spacetimedb-lib.workspace = true
spacetimedb-primitives.workspace = true
spacetimedb-schema.workspace = true
Expand Down
14 changes: 7 additions & 7 deletions crates/physical-plan/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,12 @@ pub fn compile(ast: StatementCtx<'_>) -> PhysicalCtx<'_> {
self.next.into()
}
}
let mut var = Interner {
next: 0,
names: HashMap::new(),
};
let plan = match ast.statement {
Statement::Select(expr) => compile_project_list(
&mut Interner {
next: 0,
names: HashMap::new(),
},
expr,
),
Statement::Select(expr) => compile_project_list(&mut var, expr),
_ => {
unreachable!("Only `SELECT` is implemented")
}
Expand All @@ -177,6 +175,8 @@ pub fn compile(ast: StatementCtx<'_>) -> PhysicalCtx<'_> {
PhysicalCtx {
plan,
sql: ast.sql,
vars: var.names,
source: ast.source,
planning_time: ast.planning_time,
}
}
1 change: 1 addition & 0 deletions crates/physical-plan/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod compile;
pub mod plan;
pub mod printer;
pub mod rules;
Loading