Skip to content

Commit

Permalink
Printer for the plan, ie: EXPLAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx committed Dec 23, 2024
1 parent da0f83b commit d34889f
Show file tree
Hide file tree
Showing 10 changed files with 851 additions and 32 deletions.
18 changes: 18 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 @@ -151,6 +151,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
2 changes: 2 additions & 0 deletions crates/expr/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ pub fn parse_and_type_sub(sql: &str, tx: &impl SchemaView) -> TypingResult<Proje

/// 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();
let expr = parse_and_type_sub(sql, tx)?;
Ok(StatementCtx {
statement: Statement::Select(expr),
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 @@ -173,6 +173,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 @@ -185,4 +186,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
4 changes: 4 additions & 0 deletions crates/physical-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ description = "The physical query plan for the SpacetimeDB query engine"

[dependencies]
derive_more.workspace = true
itertools.workspace = true
spacetimedb-lib.workspace = true
spacetimedb-primitives.workspace = true
spacetimedb-schema.workspace = true
spacetimedb-expr.workspace = true
spacetimedb-sql-parser.workspace = true

[dev-dependencies]
expect-test.workspace = true
1 change: 1 addition & 0 deletions crates/physical-plan/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ pub fn compile(ast: StatementCtx<'_>) -> PhysicalCtx<'_> {
plan,
sql: ast.sql,
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,2 +1,3 @@
pub mod compile;
pub mod plan;
pub mod printer;
Loading

0 comments on commit d34889f

Please sign in to comment.