Skip to content

Commit aaa038c

Browse files
Remove old query engine and vm crate
1 parent 24a6658 commit aaa038c

41 files changed

Lines changed: 260 additions & 10518 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ members = [
3838
"crates/table",
3939
"crates/testing",
4040
"crates/update",
41-
"crates/vm",
4241
"modules/benchmarks",
4342
"modules/keynote-benchmarks",
4443
"modules/perf-test",
@@ -143,7 +142,6 @@ spacetimedb-schema = { path = "crates/schema", version = "=2.0.4" }
143142
spacetimedb-standalone = { path = "crates/standalone", version = "=2.0.4" }
144143
spacetimedb-sql-parser = { path = "crates/sql-parser", version = "=2.0.4" }
145144
spacetimedb-table = { path = "crates/table", version = "=2.0.4" }
146-
spacetimedb-vm = { path = "crates/vm", version = "=2.0.4" }
147145
spacetimedb-fs-utils = { path = "crates/fs-utils", version = "=2.0.4" }
148146
spacetimedb-snapshot = { path = "crates/snapshot", version = "=2.0.4" }
149147
spacetimedb-subscription = { path = "crates/subscription", version = "=2.0.4" }

crates/bench/benches/subscription.rs

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
22
use spacetimedb::client::consume_each_list::ConsumeEachBuffer;
33
use spacetimedb::db::relational_db::RelationalDB;
44
use spacetimedb::error::DBError;
5-
use spacetimedb::host::module_host::DatabaseTableUpdate;
65
use spacetimedb::identity::AuthCtx;
76
use spacetimedb::sql::ast::SchemaViewer;
8-
use spacetimedb::subscription::query::compile_read_only_queryset;
97
use spacetimedb::subscription::row_list_builder_pool::BsatnRowListBuilderPool;
10-
use spacetimedb::subscription::subscription::ExecutionSet;
118
use spacetimedb::subscription::tx::DeltaTx;
129
use spacetimedb::subscription::{collect_table_update, TableUpdateType};
1310
use spacetimedb_bench::database::BenchDatabase as _;
1411
use spacetimedb_bench::spacetime_raw::SpacetimeRaw;
15-
use spacetimedb_client_api_messages::websocket::v1::{BsatnFormat, Compression};
12+
use spacetimedb_client_api_messages::websocket::v1::BsatnFormat;
1613
use spacetimedb_datastore::execution_context::Workload;
1714
use spacetimedb_execution::pipelined::PipelinedProject;
1815
use spacetimedb_primitives::{col_list, TableId};
1916
use spacetimedb_query::compile_subscription;
20-
use spacetimedb_sats::{bsatn, product, AlgebraicType, AlgebraicValue, ProductValue};
21-
22-
use spacetimedb_schema::table_name::TableName;
17+
use spacetimedb_sats::{bsatn, product, AlgebraicType, AlgebraicValue};
2318
#[cfg(not(target_env = "msvc"))]
2419
use tikv_jemallocator::Jemalloc;
2520

@@ -52,15 +47,6 @@ fn create_table_footprint(db: &RelationalDB) -> Result<TableId, DBError> {
5247
db.create_table_for_test("footprint", schema, indexes)
5348
}
5449

55-
fn insert_op(table_id: TableId, table_name: &str, row: ProductValue) -> DatabaseTableUpdate {
56-
DatabaseTableUpdate {
57-
table_id,
58-
table_name: TableName::for_test(table_name),
59-
inserts: [row].into(),
60-
deletes: [].into(),
61-
}
62-
}
63-
6450
fn eval(c: &mut Criterion) {
6551
let raw = SpacetimeRaw::build(false).unwrap();
6652

@@ -115,16 +101,12 @@ fn eval(c: &mut Criterion) {
115101
let footprint = AlgebraicValue::sum(1, AlgebraicValue::unit());
116102
let owner = 6u64;
117103

118-
let new_lhs_row = product!(entity_id, owner, footprint);
119-
let new_rhs_row = product!(entity_id, chunk_index, x, z, dimension);
120-
121-
let ins_lhs = insert_op(lhs, "footprint", new_lhs_row);
122-
let ins_rhs = insert_op(rhs, "location", new_rhs_row);
123-
let update = [&ins_lhs, &ins_rhs];
104+
let _new_lhs_row = product!(entity_id, owner, footprint);
105+
let _new_rhs_row = product!(entity_id, chunk_index, x, z, dimension);
124106

125107
let bsatn_rlb_pool = black_box(BsatnRowListBuilderPool::new());
126108

127-
// A benchmark runner for the new query engine
109+
// A benchmark runner for the subscription engine.
128110
let bench_query = |c: &mut Criterion, name, sql| {
129111
c.bench_function(name, |b| {
130112
let tx = raw.db.begin_tx(Workload::Subscribe);
@@ -154,20 +136,6 @@ fn eval(c: &mut Criterion) {
154136
});
155137
};
156138

157-
let bench_eval = |c: &mut Criterion, name, sql| {
158-
c.bench_function(name, |b| {
159-
let tx = raw.db.begin_tx(Workload::Update);
160-
let query = compile_read_only_queryset(&raw.db, &AuthCtx::for_testing(), &tx, sql).unwrap();
161-
let query: ExecutionSet = query.into();
162-
163-
b.iter(|| {
164-
let updates =
165-
black_box(query.eval::<BsatnFormat>(&raw.db, &tx, &bsatn_rlb_pool, None, Compression::None));
166-
updates.consume_each_list(&mut |buffer| bsatn_rlb_pool.try_put(buffer));
167-
})
168-
});
169-
};
170-
171139
// Join 1M rows on the left with 12K rows on the right.
172140
// Note, this should use an index join so as not to read the entire footprint table.
173141
let semijoin = format!(
@@ -183,66 +151,6 @@ fn eval(c: &mut Criterion) {
183151
bench_query(c, "footprint-scan", "select * from footprint");
184152
bench_query(c, "footprint-semijoin", &semijoin);
185153
bench_query(c, "index-scan-multi", index_scan_multi);
186-
187-
// To profile this benchmark for 30s
188-
// samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- full-scan --exact --profile-time=30
189-
// Iterate 1M rows.
190-
bench_eval(c, "full-scan", "select * from footprint");
191-
192-
// To profile this benchmark for 30s
193-
// samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- full-join --exact --profile-time=30
194-
// Join 1M rows on the left with 12K rows on the right.
195-
// Note, this should use an index join so as not to read the entire footprint table.
196-
let name = format!(
197-
r#"
198-
select footprint.*
199-
from footprint join location on footprint.entity_id = location.entity_id
200-
where location.chunk_index = {chunk_index}
201-
"#
202-
);
203-
bench_eval(c, "full-join", &name);
204-
205-
// To profile this benchmark for 30s
206-
// samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- incr-select --exact --profile-time=30
207-
c.bench_function("incr-select", |b| {
208-
// A passthru executed independently of the database.
209-
let select_lhs = "select * from footprint";
210-
let select_rhs = "select * from location";
211-
let tx = &raw.db.begin_tx(Workload::Update);
212-
let query_lhs = compile_read_only_queryset(&raw.db, &AuthCtx::for_testing(), tx, select_lhs).unwrap();
213-
let query_rhs = compile_read_only_queryset(&raw.db, &AuthCtx::for_testing(), tx, select_rhs).unwrap();
214-
let query = ExecutionSet::from_iter(query_lhs.into_iter().chain(query_rhs));
215-
let tx = &tx.into();
216-
217-
b.iter(|| drop(black_box(query.eval_incr_for_test(&raw.db, tx, &update, None))))
218-
});
219-
220-
// To profile this benchmark for 30s
221-
// samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- incr-join --exact --profile-time=30
222-
c.bench_function("incr-join", |b| {
223-
// Not a passthru - requires reading of database state.
224-
let join = format!(
225-
"\
226-
select footprint.* \
227-
from footprint join location on footprint.entity_id = location.entity_id \
228-
where location.chunk_index = {chunk_index}"
229-
);
230-
let tx = &raw.db.begin_tx(Workload::Update);
231-
let query = compile_read_only_queryset(&raw.db, &AuthCtx::for_testing(), tx, &join).unwrap();
232-
let query: ExecutionSet = query.into();
233-
let tx = &tx.into();
234-
235-
b.iter(|| drop(black_box(query.eval_incr_for_test(&raw.db, tx, &update, None))));
236-
});
237-
238-
// To profile this benchmark for 30s
239-
// samply record -r 10000000 cargo bench --bench=subscription --profile=profiling -- query-indexes-multi --exact --profile-time=30
240-
// Iterate 1M rows.
241-
bench_eval(
242-
c,
243-
"query-indexes-multi",
244-
"select * from location WHERE x = 0 AND z = 10000 AND dimension = 0",
245-
);
246154
}
247155

248156
criterion_group!(benches, eval);

crates/client-api/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ impl Host {
166166
.await
167167
.map_err(|e| {
168168
log::warn!("{e}");
169-
if let Some(auth_err) = e.get_auth_error() {
170-
(StatusCode::UNAUTHORIZED, auth_err.to_string())
171-
} else {
172-
(StatusCode::BAD_REQUEST, e.to_string())
173-
}
169+
(StatusCode::BAD_REQUEST, e.to_string())
174170
})?;
175171

176172
let total_duration = sql_start.elapsed();

crates/core/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ spacetimedb-query.workspace = true
3131
spacetimedb-sats = { workspace = true, features = ["serde"] }
3232
spacetimedb-schema.workspace = true
3333
spacetimedb-table.workspace = true
34-
spacetimedb-vm.workspace = true
3534
spacetimedb-snapshot.workspace = true
3635
spacetimedb-subscription.workspace = true
3736
spacetimedb-expr.workspace = true
@@ -156,7 +155,6 @@ spacetimedb-lib = { path = "../lib", features = ["proptest", "test"] }
156155
spacetimedb-sats = { path = "../sats", features = ["proptest"] }
157156
spacetimedb-commitlog = { path = "../commitlog", features = ["test"] }
158157
spacetimedb-datastore = { path = "../datastore/", features = ["test"] }
159-
spacetimedb-vm = { workspace = true, features = ["test"]}
160158

161159
criterion.workspace = true
162160
# Also as dev-dependencies for use in _this_ crate's tests.

crates/core/src/db/relational_db.rs

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use spacetimedb_lib::ConnectionId;
4242
use spacetimedb_lib::Identity;
4343
use spacetimedb_paths::server::{ReplicaDir, SnapshotsPath};
4444
use spacetimedb_primitives::*;
45-
use spacetimedb_sats::algebraic_type::fmt::fmt_algebraic_type;
4645
use spacetimedb_sats::memory_usage::MemoryUsage;
4746
use spacetimedb_sats::raw_identifier::RawIdentifier;
4847
use spacetimedb_sats::{AlgebraicType, AlgebraicValue, ProductType, ProductValue};
@@ -56,8 +55,6 @@ use spacetimedb_snapshot::{ReconstructedSnapshot, SnapshotError, SnapshotReposit
5655
use spacetimedb_table::indexes::RowPointer;
5756
use spacetimedb_table::page_pool::PagePool;
5857
use spacetimedb_table::table::{RowRef, TableScanIter};
59-
use spacetimedb_vm::errors::{ErrorType, ErrorVm};
60-
use spacetimedb_vm::ops::parse;
6158
use std::borrow::Cow;
6259
use std::io;
6360
use std::ops::{Bound, RangeBounds};
@@ -1511,32 +1508,6 @@ impl RelationalDB {
15111508
Ok(None)
15121509
}
15131510

1514-
/// Read the value of [ST_VARNAME_SLOW_QRY] from `st_var`
1515-
pub(crate) fn query_limit(&self, tx: &Tx) -> Result<Option<u64>, DBError> {
1516-
if let Some(StVarValue::U64(ms)) = self.read_var(tx, StVarName::SlowQryThreshold)? {
1517-
return Ok(Some(ms));
1518-
}
1519-
Ok(None)
1520-
}
1521-
1522-
/// Read the value of [ST_VARNAME_SLOW_SUB] from `st_var`
1523-
#[allow(dead_code)]
1524-
pub(crate) fn sub_limit(&self, tx: &Tx) -> Result<Option<u64>, DBError> {
1525-
if let Some(StVarValue::U64(ms)) = self.read_var(tx, StVarName::SlowSubThreshold)? {
1526-
return Ok(Some(ms));
1527-
}
1528-
Ok(None)
1529-
}
1530-
1531-
/// Read the value of [ST_VARNAME_SLOW_INC] from `st_var`
1532-
#[allow(dead_code)]
1533-
pub(crate) fn incr_limit(&self, tx: &Tx) -> Result<Option<u64>, DBError> {
1534-
if let Some(StVarValue::U64(ms)) = self.read_var(tx, StVarName::SlowIncThreshold)? {
1535-
return Ok(Some(ms));
1536-
}
1537-
Ok(None)
1538-
}
1539-
15401511
/// Read the value of a system variable from `st_var`
15411512
pub(crate) fn read_var(&self, tx: &Tx, name: StVarName) -> Result<Option<StVarValue>, DBError> {
15421513
if let Some(row_ref) = self
@@ -1548,31 +1519,6 @@ impl RelationalDB {
15481519
Ok(None)
15491520
}
15501521

1551-
/// Update the value of a system variable in `st_var`
1552-
pub(crate) fn write_var(&self, tx: &mut MutTx, name: StVarName, literal: &str) -> Result<(), DBError> {
1553-
let value = Self::parse_var(name, literal)?;
1554-
if let Some(row_ref) = self
1555-
.iter_by_col_eq_mut(tx, ST_VAR_ID, StVarFields::Name.col_id(), &name.into())?
1556-
.next()
1557-
{
1558-
self.delete(tx, ST_VAR_ID, [row_ref.pointer()]);
1559-
}
1560-
tx.insert_via_serialize_bsatn(ST_VAR_ID, &StVarRow { name, value })?;
1561-
Ok(())
1562-
}
1563-
1564-
/// Parse the literal representation of a system variable
1565-
fn parse_var(name: StVarName, literal: &str) -> Result<StVarValue, DBError> {
1566-
StVarValue::try_from_primitive(parse::parse(literal, &name.type_of())?).map_err(|v| {
1567-
ErrorVm::Type(ErrorType::Parse {
1568-
value: literal.to_string(),
1569-
ty: fmt_algebraic_type(&name.type_of()).to_string(),
1570-
err: format!("error parsing value: {v:?}"),
1571-
})
1572-
.into()
1573-
})
1574-
}
1575-
15761522
/// Write `rows` into a (sender) view's backing table.
15771523
///
15781524
/// # Process
@@ -2353,9 +2299,7 @@ mod tests {
23532299

23542300
use super::tests_utils::begin_mut_tx;
23552301
use super::*;
2356-
use crate::db::relational_db::tests_utils::{
2357-
begin_tx, insert, make_snapshot, with_auto_commit, with_read_only, TestDB,
2358-
};
2302+
use crate::db::relational_db::tests_utils::{begin_tx, insert, make_snapshot, TestDB};
23592303
use anyhow::bail;
23602304
use bytes::Bytes;
23612305
use commitlog::payload::txdata;
@@ -2465,18 +2409,6 @@ mod tests {
24652409
Ok(())
24662410
}
24672411

2468-
#[test]
2469-
fn test_system_variables() {
2470-
let db = TestDB::durable().expect("failed to create db");
2471-
let _ = with_auto_commit(&db, |tx| db.write_var(tx, StVarName::RowLimit, "5"));
2472-
assert_eq!(
2473-
5,
2474-
with_read_only(&db, |tx| db.row_limit(tx))
2475-
.expect("failed to read from st_var")
2476-
.expect("row_limit does not exist")
2477-
);
2478-
}
2479-
24802412
#[test]
24812413
fn test_open_twice() -> ResultTest<()> {
24822414
let stdb = TestDB::durable()?;

0 commit comments

Comments
 (0)