GeezerVison is showing github.com — Move query estimation out of core (#6500) · TNB-AR/SpacetimeDB@1a31c3a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Cargo.lock +4-1Lines changed: 4 additions & 1 deletion Collapse file Copy file name to clipboardExpand all lines: crates/core/Cargo.toml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,7 +28,7 @@ spacetimedb-metrics.workspace = true | 28 | 28 | spacetimedb-primitives.workspace = true | 29 | 29 | spacetimedb-paths.workspace = true | 30 | 30 | spacetimedb-physical-plan.workspace = true | 31 | | -spacetimedb-query.workspace = true | | 31 | +spacetimedb-query = { workspace = true, features = ["estimation"] } | 32 | 32 | spacetimedb-runtime.workspace = true | 33 | 33 | spacetimedb-sats = { workspace = true, features = ["serde"] } | 34 | 34 | spacetimedb-schema.workspace = true | |
Collapse file Copy file name to clipboardExpand all lines: crates/core/src/host/module_host.rs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,6 @@ use crate::database_logger::{DatabaseLogger, LogLevel, Record}; | 8 | 8 | use crate::db::relational_db::{RelationalDB, Tx}; | 9 | 9 | use crate::db::sql::ast::SchemaViewer; | 10 | 10 | use crate::error::DBError; | 11 | | -use crate::estimation::{check_row_limit, estimate_rows_scanned}; | 12 | 11 | use crate::hash::Hash; | 13 | 12 | use crate::host::host_controller::{CallProcedureReturn, ProcedureCallResult}; | 14 | 13 | use crate::host::scheduler::{CallScheduledFunctionError, CallScheduledFunctionResult, ScheduledFunctionParams}; | @@ -65,6 +64,7 @@ use spacetimedb_lib::metrics::ExecutionMetrics; | 65 | 64 | use spacetimedb_lib::{bsatn, ConnectionId, TimeDuration, Timestamp}; | 66 | 65 | use spacetimedb_primitives::{HttpHandlerId, ProcedureId, TableId, ViewFnPtr, ViewId}; | 67 | 66 | use spacetimedb_query::compile_subscription; | | 67 | +use spacetimedb_query::estimation::{check_row_limit, estimate_rows_scanned}; | 68 | 68 | use spacetimedb_sats::raw_identifier::RawIdentifier; | 69 | 69 | use spacetimedb_sats::{AlgebraicType, AlgebraicTypeRef, ProductValue, Typespace}; | 70 | 70 | use spacetimedb_schema::auto_migrate::{AutoMigrateError, MigrationPolicy}; | |
Collapse file Copy file name to clipboardExpand all lines: crates/core/src/lib.rs -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,6 @@ pub mod callgrind_flag; | 15 | 15 | pub mod client; | 16 | 16 | pub mod config; | 17 | 17 | pub mod database_logger; | 18 | | -pub mod estimation; | 19 | 18 | pub mod host; | 20 | 19 | pub mod module_host_context; | 21 | 20 | pub mod replica_context; | |
Collapse file Copy file name to clipboardExpand all lines: crates/core/src/sql/execute.rs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,6 @@ use std::time::Duration; | 4 | 4 | use crate::db::sql::ast::SchemaViewer; | 5 | 5 | use crate::energy::FunctionBudget; | 6 | 6 | use crate::error::DBError; | 7 | | -use crate::estimation::{check_row_limit, estimate_rows_scanned}; | 8 | 7 | use crate::host::module_host::{ | 9 | 8 | DatabaseUpdate, EventStatus, ModuleEvent, ModuleFunctionCall, RefInstance, ViewCallResult, ViewOutcome, | 10 | 9 | WasmInstance, | @@ -22,6 +21,7 @@ use spacetimedb_lib::identity::AuthCtx; | 22 | 21 | use spacetimedb_lib::metrics::ExecutionMetrics; | 23 | 22 | use spacetimedb_lib::Timestamp; | 24 | 23 | use spacetimedb_lib::{AlgebraicType, ProductType, ProductValue}; | | 24 | +use spacetimedb_query::estimation::{check_row_limit, estimate_rows_scanned}; | 25 | 25 | use spacetimedb_query::{compile_sql_stmt, execute_dml_stmt, execute_select_stmt}; | 26 | 26 | use spacetimedb_sats::raw_identifier::RawIdentifier; | 27 | 27 | use tokio::sync::oneshot; | |
Collapse file Copy file name to clipboardExpand all lines: crates/core/src/subscription/module_subscription_actor.rs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,6 @@ use crate::client::messages::{ | 14 | 14 | use crate::client::{ClientActorId, ClientConnectionSender, Protocol, WsVersion}; | 15 | 15 | use crate::db::relational_db::{MutTx, RelationalDB, Tx}; | 16 | 16 | use crate::error::DBError; | 17 | | -use crate::estimation::{check_row_limit, estimate_rows_scanned}; | 18 | 17 | use crate::host::module_host::{DatabaseUpdate, EventStatus, ModuleEvent, RefInstance, WasmInstance}; | 19 | 18 | use crate::host::{self, ModuleHost}; | 20 | 19 | use crate::subscription::query::is_subscribe_to_all_tables; | @@ -42,6 +41,7 @@ use spacetimedb_lib::Identity; | 42 | 41 | use spacetimedb_lib::{bsatn, identity::AuthCtx}; | 43 | 42 | use spacetimedb_metrics::utils::IntGaugeExt; | 44 | 43 | use spacetimedb_physical_plan::plan::ProjectPlan; | | 44 | +use spacetimedb_query::estimation::{check_row_limit, estimate_rows_scanned}; | 45 | 45 | use spacetimedb_schema::def::RawModuleDefVersion; | 46 | 46 | use spacetimedb_table::static_assert_size; | 47 | 47 | use std::{ | |
Collapse file Copy file name to clipboardExpand all lines: crates/query/Cargo.toml +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,12 +8,21 @@ description = "Top level crate for invoking the query engine and optimizer" | 8 | 8 |
| 9 | 9 | [dependencies] | 10 | 10 | anyhow.workspace = true | | 11 | +spacetimedb-datastore = { workspace = true, optional = true } | | 12 | +spacetimedb-engine = { workspace = true, optional = true } | 11 | 13 | spacetimedb-execution.workspace = true | 12 | 14 | spacetimedb-expr.workspace = true | 13 | 15 | spacetimedb-lib.workspace = true | 14 | 16 | spacetimedb-primitives.workspace = true | 15 | 17 | spacetimedb-physical-plan.workspace = true | 16 | 18 | spacetimedb-schema.workspace = true | 17 | 19 |
| | 20 | +[dev-dependencies] | | 21 | +spacetimedb-engine = { path = "../engine", features = ["test"] } | | 22 | + | | 23 | +[features] | | 24 | +# Native engine integration; leave disabled for portable datastore builds. | | 25 | +estimation = ["dep:spacetimedb-datastore", "dep:spacetimedb-engine"] | | 26 | + | 18 | 27 | [lints] | 19 | 28 | workspace = true |
Collapse file Copy file name to clipboardExpand all lines: crates/query/src/estimation.rs +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -use crate::{ | 2 | | - db::relational_db::{RelationalDB, Tx}, | | 1 | +use spacetimedb_datastore::locking_tx_datastore::{state_view::StateView as _, NumDistinctValues}; | | 2 | +use spacetimedb_engine::{ | 3 | 3 | error::DBError, | | 4 | + relational_db::{RelationalDB, Tx}, | 4 | 5 | }; | 5 | | -use spacetimedb_datastore::locking_tx_datastore::{state_view::StateView as _, NumDistinctValues}; | 6 | 6 | use spacetimedb_lib::{identity::AuthCtx, query::Delta}; | 7 | 7 | use spacetimedb_physical_plan::plan::{HashJoin, IndexProbe, IxJoin, IxScan, PhysicalPlan, TableScan}; | 8 | 8 | use spacetimedb_primitives::{ColList, TableId}; | @@ -132,13 +132,13 @@ fn index_row_est(tx: &Tx, table_id: TableId, cols: &ColList) -> u64 { | 132 | 132 | #[cfg(test)] | 133 | 133 | mod tests { | 134 | 134 | use super::{estimate_rows_scanned, row_estimate}; | 135 | | - use crate::db::relational_db::tests_utils::{begin_tx, insert, with_auto_commit}; | 136 | | - use crate::db::relational_db::{tests_utils::TestDB, RelationalDB}; | 137 | | - use crate::db::sql::ast::SchemaViewer; | 138 | | - use crate::error::DBError; | | 135 | + use crate::compile_subscription; | | 136 | + use spacetimedb_engine::error::DBError; | | 137 | + use spacetimedb_engine::relational_db::tests_utils::{begin_tx, insert, with_auto_commit}; | | 138 | + use spacetimedb_engine::relational_db::{tests_utils::TestDB, RelationalDB}; | | 139 | + use spacetimedb_engine::sql::ast::SchemaViewer; | | 140 | + use spacetimedb_lib::sats::product; | 139 | 141 | use spacetimedb_lib::{identity::AuthCtx, AlgebraicType}; | 140 | | - use spacetimedb_query::compile_subscription; | 141 | | - use spacetimedb_sats::product; | 142 | 142 |
| 143 | 143 | fn in_mem_db() -> TestDB { | 144 | 144 | TestDB::in_memory().expect("failed to make test db") | |
Collapse file Copy file name to clipboardExpand all lines: crates/query/src/lib.rs +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#[cfg(feature = "estimation")] | | 2 | +pub mod estimation; | | 3 | + | 1 | 4 | use anyhow::{bail, Result}; | 2 | 5 | use spacetimedb_execution::{ | 3 | 6 | dml::{MutDatastore, MutExecutor}, | |
Collapse file Copy file name to clipboardExpand all lines: crates/test-datastore/Cargo.toml +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,12 +12,13 @@ path = "src/lib.rs" | 12 | 12 | bench = false | 13 | 13 |
| 14 | 14 | [dependencies] | 15 | | -spacetimedb_core = { package = "spacetimedb-core", path = "../core", version = "=2.16.0", features = ["test"] } | | 15 | +spacetimedb-engine = { workspace = true, features = ["test"] } | 16 | 16 | spacetimedb-datastore.workspace = true | | 17 | +spacetimedb-execution.workspace = true | 17 | 18 | spacetimedb-expr.workspace = true | 18 | 19 | spacetimedb-lib.workspace = true | 19 | 20 | spacetimedb-primitives.workspace = true | 20 | | -spacetimedb-query.workspace = true | | 21 | +spacetimedb-query = { workspace = true, features = ["estimation"] } | 21 | 22 | spacetimedb-schema.workspace = true | 22 | 23 |
| 23 | 24 | anyhow.workspace = true | |
|