Commit Graph

441 Commits

Author SHA1 Message Date
Mario Montoya 114aa994bf Fix output of binary, Identity, Address for SQL output and the 'Display' of them to show a full hex value (#1087) 2024-06-10 16:49:46 +00:00
joshua-spacetime c2831d06d0 test(1329): Row limit from system table (#1355) 2024-06-10 10:31:18 +00:00
Kim Altintop 1044ebc652 core: Store address, owner and program bytes in st_module (#1305) 2024-06-10 10:25:16 +00:00
joshua-spacetime ccaad88130 fix(1353): Remove underscore based table access checks (#1354) 2024-06-10 09:58:51 +00:00
joshua-spacetime 61ee5def83 feat: System table based slow query logging (#1350) 2024-06-07 21:37:34 +00:00
Ingvar Stepanyan d1033b5d93 Shared C# codegen for BSATN (#1312)
Signed-off-by: Ingvar Stepanyan <me@rreverser.com>
Co-authored-by: james gilles <jameshgilles@gmail.com>
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-06-07 19:22:02 +00:00
joshua-spacetime b3339c80bc feat(1329): System table for system variables (#1342)
Closes #1329.

Used to persist global parameters for slow query logging and cardinality limits.
2024-06-06 20:30:07 +00:00
Mazdak Farrokhzad f08644f840 make update_database insensitive to table access changes (#1338) 2024-06-05 16:31:07 +00:00
Phoebe Goldman 697a581886 Make both TX offset counters agree (#1332)
* Make both TX offset counters agree

Prior to this commit, `CommittedState::next_tx_offset` got out of sync
with the commitlog/durability's notion of the tx offset,
because the former counted all committed TXes,
while the latter excluded certain empty TXes
(namely, empty TXes
which were not `__identity_connected__` or `__identity_disconnected__` reducers).

With this commit, the skipping logic is moved earlier into `CommittedState`,
so that it can maintain a counter consistent with that used by the commitlog.

* Remove duplicated increment
2024-06-04 17:57:00 +00:00
Jeremie Pelletier da23401368 Jeremie/notify sql (#1198)
* Notify subscriptions from SQL code path

* Remove blocking_broadcast_event

(From another PR, but helps tests to pass)

* Update from review

* Update from rebase

* cargo fmt

* cargo fmt

* cargo fmt

* update space.rs
2024-06-03 22:51:05 +00:00
Phoebe Goldman 18aa1d4299 Fix commitlog fold_transactions_from ignoring requested offset (#1330)
* Fix commitlog `fold_transactions_from` ignoring requested offset

Prior to this commit, `fold_transactions_from` on a durability backed by a commitlog
would discard the requested offset and unconditionally yield all txes in the relevant segments.

This commit changes that behavior so that `fold_transactions_from`
skips commitlog commits (which contain many txes) less than the reqested offset,
and skips txes using `consume_record`.

* Add `Decoder::skip_record`

Lucky I asked Kim whether I was using `consume_record` and `decode_record` correctly,
because I wasn't.

This commit adds methods to `Decoder` and `Visitor` for skipping records and rows,
causing them to be extracted from the reader but not folded.

* Fix test

Add new methods to `Decoder` and `Visitor` hidden away in a test I missed.
2024-06-03 22:37:43 +00:00
Mazdak Farrokhzad be9c958d21 Flatten ColumnOp so that we box less (#1234) 2024-06-03 17:36:44 +00:00
Mazdak Farrokhzad 89aecd15e3 Split ColumnOp into one with row indices and one with FieldName & other enabled changes (#1207)
* 1. Split ColumnOp into ColumnOp & FieldOp, former storing ColId
2. Shrink SqlAst to 80 bytes, so it can be passed in registers
3. Store end-result Header in IndexSemiJoin
4. Remove operational use of Header in ColumnOp & build_query
5. Simplify RowRef::{get, project, project_owned}

* Make parts of build_query actually infallible.

1. Make IndexSemiJoin::filter infallible.
2. Make ColumnOp::compare and friends infallible.
3. Make RowRef::{get, project, project_owned} infallible.

* Make RelOps::next itself infallible

* 1. with_select{_cmp}: ensure type safety o query exec cannot panic
2. Document RelValue::{get, read_or_take_column, project_owned}
3. Refactor optimize_select
4. Ensure in optimize_select that conditions are merged with preceding selects

* remove RelOps::{head, row_count}; head is redundant & row_count is useless

* remove Relation trait; it does not carry its weight

* make build_query infallible

* simplify IndexSemiJoin, make it slightly less branchy

* simplify try_index_join

* split IndexSemiJoin into Left & Right parts

* move get_field_pos to test code

* move test version of build_query to test code
2024-06-03 16:45:32 +00:00
Zeke Foppa 2b66851560 More trace logs for TX locking (#1253)
* [bfops/logtrace]: do thing

* [bfops/logtrace]: empty

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-06-03 16:43:10 +00:00
Mazdak Farrokhzad f6b39c0abc IndexJoin/JoinInner: store ColId (#1166)
* IndexJoin/JoinInner: store ColId

* QueryExpr: carry full Header info for resulting query

* refactor and dedup build_query
2024-06-03 15:26:49 +00:00
Mazdak Farrokhzad 5e47b61f8a Tables only become public explicitly via #[spacetimedb(table(public))] (#1278)
* make user tables private by default and define privacy via attribute

* switch to spacetimedb(table(public)) syntax

* accept codegen snap changes

* sdk: use public in define_tables!

* bindings-macro: adjust some doc comments

* sdk-test-connect-disconnect: make Connected/Disconnected public tables

* Make Public Private again
2024-06-03 11:22:58 +00:00
Noa a8549457e9 Re-add execute_sql_mut_tx (#1313) 2024-06-03 09:49:03 +00:00
Mazdak Farrokhzad 74bcecd9d4 Restrict multi-col index scans to = (OpCmp::Eq) on all columns (#1316)
* add test test_multi_column_two_ranges, which should fail but doesn't

* restrict multi-col index scans to OpCmp::Eq
2024-06-01 13:25:06 +00:00
Shubham Mishra cf4b9aa282 metric for table size (#1319)
* table size metric

* feld blob_store_bytes in table

* address comments

* NumBlobBytes type

* table size metrics: adjust comments, visibility + harden test

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-05-31 17:44:12 +00:00
joshua-spacetime 6512f35c6b feat(1231): Add a configurable row limit for queries (#1293)
Closes #1231.

Queries that are estimated to exceed this row limit are rejected.
And the same holds for subscriptions.
2024-05-30 21:35:48 +00:00
Mazdak Farrokhzad 4ac49e564d execution_set.check_auth(...) on initial subscription (#1274) 2024-05-28 19:44:32 +00:00
Mazdak Farrokhzad c8225db8f5 1. Reduce visibilities, preparing to extract datastore crate (#1306)
2. More direct imports, preparing to extract datastore crate
3. Remove some dead code
2024-05-28 17:46:07 +00:00
Mazdak Farrokhzad 0e74beed16 merge_apply_inserts/deletes: do metrics work once per table, not per row (#1286)
* merge_apply_inserts: bulk update metrics

* merge_apply_deletes: bulk update metrics
2024-05-28 08:49:22 +00:00
Shubham Mishra 1f2331634d due cleanup (#1301) 2024-05-27 18:21:17 +00:00
Noa 55b7cbe486 Let ProgramStorage::external be async (#1291)
* Let ProgramStorage::external be async

* Remove core::object_db

* Remove odb_rocksdb feature

* Fix typo

* More resilient conflict avoidance
2024-05-24 21:28:54 +00:00
Shubham Mishra 8ecee762f1 Shub/st connected clients (#1288)
* trait modification

* st clients

* error handling

* fix

* make connect transactional

* handle empty reducer

* test

* fix tests
2024-05-24 18:03:31 +00:00
Zeke Foppa 8c3fa75907 Remove incremental-joins.md (#1296)
* [bfops/rm-include-str]: empty

* [bfops/rm-include-str]: do thing

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-24 17:03:09 +00:00
Kim Altintop 48a2b98d3c Disconnect dangling clients (#1132)
When replaying the commitlog, keep track of unpaired connect/disconnect
calls and call disconnect when instantiating the module.
2024-05-23 18:53:55 +00:00
joshua-spacetime 88a8adad70 feat(1231): Basic query cardinality estimation (#1273)
* feat(1231): Basic query cardinality estimation

This patch implements basic cardinality estimation for QueryExpr.
It utilizes table cardinalities and number of distinct values for index related operators.

* estimation tests: dedup + define constants for readability

* row_est: simplify with slice patterns

* fn ndv -> fn num_distinict_values

* simplify TypedIndex::num_keys

* is_range -> is_point (invert) + fuse arms in row_est

* estimation: fix logic for IndexJoin

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-05-23 08:49:07 +00:00
Noa 471f4ff2ca recv-style abi (#1002)
* Bump module abi version

* recv abi module side

* recv abi host side

* Update csharp module sdk

* Fix name

* Address comments
2024-05-22 23:01:44 +00:00
Noa 6b1a3d3896 Module hotswapping (#1147) 2024-05-22 17:49:35 +00:00
Mazdak Farrokhzad 9257208b6e 1. Privatize st_*_schema functions, only used in system_tables() now. (#1263)
2. Only call system_tables() once in bootstrap_system_tables.
3. Take `TableId` by value more
4. Rename `table_exists` -> `table_name`
5. Dedup `table_name` by using `get_schema()`.
6. Other misc deduping.
2024-05-22 15:48:39 +00:00
Kim Altintop edbca25f1a core: Reserve sequence range for system tables (#1265)
Reserves an unreasonably large number of sequence values for use by system
tables. This means that user-created tables will draw id values starting
from the reserved range + 1, as opposed to number of values taken by
system tables + 1.

Adding new system tables is thus unlikely to interfere with already-assigned
values in existing databases.
2024-05-22 06:35:59 +00:00
Kim Altintop 2de147522d core: Collapse DBIC into HostController (#1186)
Make it so `HostController` manages both the module host (wasm
machinery) and the database (`RelationalDB` / `DatabaseInstanceContext`)
of spacetime databases deployed to a server.

The `DatabaseInstanceContextController` (DBIC) is removed in the
process.

This allows to make database accesses panic-safe, in that uncaught
panics will cause all resouces to be released and the database to be
restarted on subsequent access. This is a prerequisite for #985.

It also allows to move towards storage of the module binary directly in
the database / commitlog. This patch, however, makes some contortions in
order to **not** introduce a breaking change just yet.
2024-05-21 17:30:02 +00:00
Mazdak Farrokhzad ebc921849e privatize Table::row_layout + related BTreeIndex refactoring (#1262) 2024-05-20 18:44:04 +00:00
Noa f0c182e2b0 Atomically downgrade lock when committing tx to prevent deadlock (#1252)
* Atomically downgrade lock when committing tx to prevent deadlock

* Address review
2024-05-20 16:59:07 +00:00
Mazdak Farrokhzad e109385c1e remove BTreeIndex::name again (#1251) 2024-05-20 15:52:57 +00:00
Mazdak Farrokhzad 267cf651b8 simplify MutTxId::table_exists (#1246) 2024-05-17 18:22:05 +00:00
Shubham Mishra 0c0567ecbf row_count field to table (#1242)
* rowcount

* added tests
2024-05-17 17:48:58 +00:00
Piotr Sarnacki d08e9845a4 Always send TransactionUpdate to the sender (#1111)
* Always send TransactionUpdate to the sender

This commit changes transaction update broadcast to always send an
update to the sender, even if the sender is not subscribed to any
data that was committed. In such case the transaction update is sent
with an empty database update.

* Remove debug printlns

* Update code after rebase

* Fix test

* Update crates/core/src/subscription/module_subscription_manager.rs

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Piotr Sarnacki <drogus@gmail.com>

* Extract sending message with error handing in module_subscription_manager

* Bring back a new line

* SDK test that the client is notified of a reducer it called

* cleanup subscription code a bit

* Fix merge problem

* Lint + fmt

* Fix test

---------

Signed-off-by: Piotr Sarnacki <drogus@gmail.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-05-16 12:35:03 +00:00
Mazdak Farrokhzad 5bf6b6cae8 add compile_join_with_diff_col_names test (#1238) 2024-05-15 18:34:27 +00:00
Mazdak Farrokhzad 9546a22e17 refactor compile_read_only_query: dedup SideEffect errors (#1235) 2024-05-15 13:48:02 +00:00
joshua-spacetime 401ffe2709 feat(1229): Double client channel capacity (#1230)
Closes #1229.

And log warning when client channel capacity is exceeded.
2024-05-14 16:54:46 +00:00
Noa b3ea0f515f Fix select * from * (#1218)
* Add SDK test for `SELECT * FROM *`

Which doesn't pass, because we broke it.

* Fix select * from *

---------

Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-05-14 04:38:15 +00:00
Kim Altintop 61613ca7a8 commitlog: Allow folds to not allocate Mutations values (#1215)
The documentation promised to not collect payload values during folds
(i.e. replaying), but the code did so anyway. This patch makes it so
only values required to satisfy the `Visitor` trait are allocated when
folding.
2024-05-13 09:35:09 +00:00
Mazdak Farrokhzad 4e444bdddd CrudExpr::{Delete, Insert, Update}: only DbTables are possible, so cleanup InMem path (#1211)
* remove dead code wrt. Table

* simplify DbProgram: Insert/Update/Delete only use DbTables

* consistency: move CrudExpr::Update logic to own function

* use TxMode::unwrap_mut more
2024-05-10 00:04:47 +00:00
Noa 3b754f10b1 Bump to Rust 1.78 (#1205)
* Bump to rust 1.78

* Fix lints
2024-05-08 14:20:12 +00:00
Mazdak Farrokhzad 6dce129494 From.{join => joins} + remove Option layer + Remove RelOps::try_fold (#1208)
* refactor From sql ast type

* remove RelOps.:try_fold (dead code)
2024-05-07 16:26:27 +00:00
joshua-spacetime 9ce8fc8db7 feat(1168): Track subscription query duration for each reducer (#1195)
Closes #1168.
2024-05-03 18:24:45 +00:00
Mazdak Farrokhzad e258262556 perf(JoinInner): use AVs for keys instead of PVs (#1194)
* perf(JoinInner): use AVs for keys instead of PVs

* Remove stale comment.

Co-authored-by: james gilles <jameshgilles@gmail.com>
Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: james gilles <jameshgilles@gmail.com>
2024-05-02 21:00:34 +00:00