Commit Graph

686 Commits

Author SHA1 Message Date
Zeke Foppa c1dfd8fddc Add a Testing section to the PR template (#898)
* [bfops/testing-in-template]: add testing to PR template

* Add Phoebe's suggestion

Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Zeke Foppa <196249+bfops@users.noreply.github.com>

---------

Signed-off-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2024-03-14 22:43:28 +00:00
Mazdak Farrokhzad 96b4f099b0 build_query, IndexScan, mem table: fix bug, avoid ColumnOp (#980) 2024-03-14 21:21:03 +00:00
Zeke Foppa 9c82e02ac8 spacetime publish: Add --wasm-file flag (#883)
* [bfops/publish-wasm]: commit

* [bfops/publish-wasm]: tweaks

* [bfops/publish-wasm]: rename

* [bfops/publish-wasm]: uncommitted changes

* [bfops/publish-wasm]: updates

* [bfops/publish-wasm]: fix

* [bfops/publish-wasm]: review

* [bfops/publish-wasm]: review
2024-03-14 21:08:53 +00:00
Mazdak Farrokhzad a552697550 simplify RelOps<'a> for CatalogCursor<I> (#979) 2024-03-14 20:17:54 +00:00
Mazdak Farrokhzad c2afe7d83a iter_filtered_chunks: avoid PVs (#978) 2024-03-14 20:09:01 +00:00
Mazdak Farrokhzad a05aed4e9a Code motion: QueryCode => QueryExpr; CrudCode => CrudExpr (#975)
* QueryCode.{table -> source}

* nix QueryCode; identical to QueryExpr

* nix CrudCode; use identical CrudExpr instead
2024-03-14 18:16:04 +00:00
Noa 540c519002 Rewrite smoketests as python unittests (#692)
* Rewrite smoketests as python unittests

* Get all tests working and do some work on parallel unittest

* Give up on parallel unittests

* Fix CI + address comments

* Fix skip-clippy arg confusion (just use the env var)

* fix ci

* Add comments
2024-03-14 02:47:38 +00:00
Mario Montoya f1226a056c Fix bench for location, restore single-column indexes (#967)
* Fix bench for location, restore single-column indexes

* Typo
2024-03-13 16:39:00 +00:00
joshua-spacetime 1066964f17 perf(816): Compile inner joins ahead of time for incremental evaluation (#964)
Joins of two delta tables are compiled to an inner join.
Their ahead of time compilation was not handled as part of #938.
2024-03-13 15:00:23 +00:00
joshua-spacetime af4a1a6425 test(954): Incremental evaluation for index joins (#958)
Adds a test for a tx that generates inserts and deletes for both tables of the join.
2024-03-12 23:14:16 +00:00
joshua-spacetime a563eb22d3 fix: Incremental evaluation for index joins (#957)
Closes #954.

I previously avoided the evaluation of certain delta table joins as an optimization,
which relied on the fact that a tx would not include inserts and deletes for both tables,
which of course is not generally correct.

This patch includes the fully general solution.
2024-03-12 22:14:35 +00:00
Phoebe Goldman 8994418136 Increase sdk tests' timeout to 60 seconds (#956)
We're seeing intermittent failures of the SDK tests in CI due to timeouts.
The timeout is meant only to fail if an expected event never happens;
the SDK tests are not interested in measuring performance at all.

This commit doubles the timeout from 30 to 60 seconds,
in the hopes that we will see fewer false failures.
2024-03-12 15:06:36 +00:00
joshua-spacetime ba5ad054af refactor: Incremental evaluation tests for index joins (#952)
No functionality has been modified.
This patch just makes incremental eval test cases clearer and easier to extend.
2024-03-12 14:16:06 +00:00
Noa 987d742baa Also poll handle_queue while flushing (#947)
* Also poll handle_queue while flushing

* Apply suggestions from code review

Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Noa <coolreader18@gmail.com>

---------

Signed-off-by: Noa <coolreader18@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2024-03-08 21:09:30 +00:00
Mario Montoya 891f6b8931 Truly remove perfcnt (#946) 2024-03-08 20:26:30 +00:00
joshua-spacetime 6098bab296 perf: Update magic constant for join rewrite (#944) 2024-03-08 02:03:17 +00:00
joshua-spacetime 6a2af38c55 chore: Remove instrumentation from subscription eval hot path (#945) 2024-03-08 01:33:39 +00:00
joshua-spacetime 0af87d2306 perf: Make op_type special case fast for selections (#943)
As an optimization,
because we do not support strict projections in subscription queries,
selections may always assume that the op_type field is last,
when removing it.
2024-03-07 21:50:24 +00:00
james gilles 1611d10713 Remove perfcnt for now (#941) 2024-03-07 21:16:58 +00:00
joshua-spacetime bba5892f26 chore: Header does not need to be Ord (#942) 2024-03-07 20:58:27 +00:00
Phoebe Goldman 8d5b33e35d Incremental joins: compile once, run repeatedly. (#938)
* Incremental joins: compile once, run repeatedly.

Well, more like, compile 3 times, run repeatedly, but 3 is approximately 1.

This commit re-writes `IncrementalJoin` to be a re-usable representation
of a query plan for an incremental join,
where before it was a one-off worker for the same.

`IncrementalJoin` stores three copies of the query, compiled for `MemTable * DbTable`,
`DbTable * MemTable` and `MemTable * MemTable`.

Related to this change, `eval_incr` no longer needs an `AuthCtx`,
because we check permissions during query compilation, not execution,
and all query planning is now done ahead of time during `add_subscriber`.
As a result, many callsites, especially in tests, which used to pass an `AuthCtx`
no longer do so.

* `IncrementalJoin`: save `MemTable` headers to avoid recomputing

* Don't include `__op_type` column in incremental joins

Incremental joins never used the `__op_type` column,
as they separate deletes from inserts and eval them as separate queries.

This commit causes incremental joins to no longer include the `__op_type` column
in their `MemTable`s at all,
which simplifies the code and should remove some allocations.

* Remove `pub` on test `run_query` helper.

The module's not `pub`, so it was a pointless qualifier.
2024-03-07 17:47:49 +00:00
joshua-spacetime 30c7338682 chore: Remove debug instrumentation from hot path (#936)
Removes most instrumentation from RelationalDB,
but keeps all pre-existing instrumentation of the wasm api.
2024-03-07 01:23:01 +00:00
Noa c6c0ba3051 Kick clients that are backing up their message channel (#930)
* Wrap ClientConnectionSender in an Arc everywhere

* Kick clients that are backing up their message channel

* Set tcp nodelay on incoming sockets
2024-03-06 22:39:17 +00:00
Phoebe Goldman 43eafda15b Avoid Header::find_pos_by_name in eval_incr. (#935)
Prior to this commit, `to_mem_table_with_op_type` would call `Header::find_pos_by_name`
to locate the `__op_type` column, if it existed.
This was slow, as `Header::find_pos_by_name` is a linear scan in increasing order,
and the `__op_type` column is always either last or not present,
so `to_mem_table_with_op_type` would traverse every column in the `Header`.
This happened during every incremental evaluation for every query.

With this commit, we rely on the fact that `__op_type` is always the last column if present,
and check only the last column of the header.
2024-03-06 21:37:57 +00:00
John Detter 4c547f02e6 Improve generate help text (#934)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-03-06 17:22:16 +00:00
Phoebe Goldman f657e95e63 Single-table subscription queries: plan once, run repeatedly (#928)
* Single-table subscription queries: plan once, run repeatedly

Prior to this commit, every call to `ExecutionUnit::eval_incr`
re-invoked the query planner to convert its `eval` plan
into a plan suitable for reading from a `MemTable` of updates.

With this commit, specifically for single-table select queries,
we invoke the query planner once during `ExecutionUnit::new`,
and store the resuling `eval_incr_plan` for repeated use.

A follow-up will do the same for multi-table semijoins.

* Docstrings for `SourceSet::len` and `::is_empty`

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>

* Compile select queries all the way to `QueryCode` ahead of time

---------

Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-03-06 16:58:25 +00:00
Shubham Mishra 71d435d096 proto changes (#924)
* proto changes

* messageId -> requestId

* fix oneoffquery

* add metrics for subscription

* requestId for reducer

* timer for reducer

* revert oneOffQeury related changes

* request_id u32 -> bytes

* use default RequestId for rust sdk

* added json changes

* added test

* clippy
2024-03-06 16:13:52 +00:00
Noa 5bcd5e2002 Use recv_many in ws_client_actor (#913) 2024-03-05 22:00:18 +00:00
Mazdak Farrokhzad b485ca20e8 Re-land mult-col index selection for queries (#918)
* Revert "Revert "Adding an index selector that take in account multi-column indexes (and improve the `query!` macro) (#694)" (#914)"

This reverts commit 8e5ce79df4.

* drive-by: refactor impl From<IndexScan> for ColumnOp

* reactor IndexScan bounds structure

* remove temp allocation in extract_fields

* skip index scan for NotEq

* drive-by: simplify Select

* clarify unreachable!(...) for NotEq

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>

* address Joshua's review + refactor compiler tests

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-03-05 18:39:58 +00:00
joshua-spacetime 313f592db9 perf(747): Single query execution for multiple subscriptions (#917)
Closes #747.

Before this change,
we would evaluate each and every query,
for each and every subscription,
on each and every row update.

If N subscriptions had a query Q in common,
it would be evaluated N different times.

With this change,
distinct queries are evaluated once,
and the results copied for each client.

So in the example above, Q would be evaluated once,
with the results transmitted to N different clients.
2024-03-05 16:52:24 +00:00
Mazdak Farrokhzad f2a75f7f33 take AV by ref in iter_by_col_eq (#925) 2024-03-05 10:46:54 +00:00
Phoebe Goldman 9afbfa7b3c Remove Tables from query plans (#912)
* First step towards removing `Table` from query plans

Rework `SourceExpr` to be a logical placeholder for a table,
rather than a table itself.

Make query eval functions take an additional argument, a set of tables.
When evaluating a `SourceExpr` to a table, they will treat the `SourceExpr`
as a reference into the set of sources, and use the referred table.

This commit modifies only the VM crate; modifications to `core` are forthcoming.
It's possible that this commit's scheme for referring to `SourceExpr`s
will need to change,
as currently it forbids duplicate `SourceExpr`s,
which I think might occur during index joins.

* `SourceBuilder` interface for assigning `SourceId`s.

* Integrate new query plan repr into `core`

* Put `DbTable` back in the AST; only `MemTable` is separate

Per review from Joshua, this commit makes `SourceExpr` into an enum
similar to the previous definition, with a `DbTable(DbTable)` variant.
Indirection to a `SourceSet` is imposed only for the `MemTable` variant.

This sould make the PR's overall diff much simpler
(assuming I haven't inadvertently made any changes
in the process of reverting the `DbTable` code paths).

Related to the above, this PR simplifies `SourceSet`.
`SourceSet` now holds a `Vec<Option<MemTable>>`, where previously
it was a transparent newtype around `[Option<Table>]`.
This change eliminates the need for unsafe unsized conversions,
removes `SourceBuilder`,
and causes `SourceSet` to be uniformly consumed by the high-level query eval operators,
where previously `SourceSet`s had to be semi-reusable
because they could contain `DbTable`s.

* Per Mazdak's review, docs!
2024-03-04 20:33:14 +00:00
Mario Montoya 7a5b66e2e3 Fix the RowCount estimation for select operator (#900)
* Fix the RowCount estimation for select operator

* Update crates/vm/src/rel_ops.rs

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>

---------

Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-03-04 16:26:19 +00:00
John Detter 8e5ce79df4 Revert "Adding an index selector that take in account multi-column indexes (and improve the query! macro) (#694)" (#914)
This reverts commit 726080dadc.

Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-03-01 20:26:24 +00:00
Mario Montoya 726080dadc Adding an index selector that take in account multi-column indexes (and improve the query! macro) (#694)
* Adding an index selector that take in account multi-column indexes (and improve the query! macro)

* move select_best_index to vm/src/expr.rs; get rid of OpCmpIdx

* refactor test best_index

* simplify best_index* tests more

* create_table_multi_index: use ColListBuilder

* move & simplify create_table_multi_index

* simplify assert_index_scan + uses

* remove create_table, twas dead code

* ColumnOpFlat: use SmallVec instead

* simplify ScanIndex

* simplify best_index_range

* Add test for sql + joins + multi-index and fix invalid ambiguos field error

* slightly refactor select_best_index

* remove nonempty dependency

* Add test that actually run the multi-column sql

* Adding benchmark for multi vs many indexes

* simplify create_table_for_test*

* Add comments

* impl new algo for select_best_index + clone less

* improve select_best_index docs

* ScanIndex -> ScanOrIndex

* simplify is_sargable + use smallvec more

* let make_index handle a single ScanOrIndex

* make index stuff more private + remove dead code

* select_best_index: return IndexColumnOp directly; nix ScanOrindex -- this removes an allocation

* do not reconstruct scan argument; avoid heap allocations

* borrow ColList in IndexArgument + avoid temp alloc in is_sargable

* optmize_select: remove Cow from fields_found

* is_sargable: reuse allocation from extract_fields

* rename is_sargable, avoid temp fields_found allocs, simplify optmize_select

* fix subscription benches

* drive-by refactor benches/subscription

* Keep a single benchmark for location

* Squashed commit of the following:

commit e54b09bab2
Author: Mario Montoya <mamcx@elmalabarista.com>
Date:   Thu Feb 29 20:19:24 2024 -0500

    Correctly show the error for AmbiguousField and simplify the code (#910)

commit 48a205a818
Author: Kim Altintop <kim@eagain.io>
Date:   Thu Feb 29 19:32:21 2024 +0100

    core: Fix host controller to not replace module if lifecyle hooks failed (#904)

    * core: Fix host controller to not replace module if lifecyle hooks failed

    Previously, `spawn_module_host` would unconditionally insert the new
    module into the controller state, and not remove it if the lifecycle
    hooks (`init_database` / `update_database`) returned an error.

    This would mean that the module code was replaced with the new one, even
    if it should be rejected because the schema was not updated or the init
    / update reducer failed.

    Fix this by starting the module, and later "committing" it to the
    controller state in two phases.

    * Add commentary about database mutations / transactionality

---------

Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-03-01 17:46:24 +00:00
Mario Montoya e54b09bab2 Correctly show the error for AmbiguousField and simplify the code (#910) 2024-03-01 01:19:24 +00:00
Kim Altintop 48a205a818 core: Fix host controller to not replace module if lifecyle hooks failed (#904)
* core: Fix host controller to not replace module if lifecyle hooks failed

Previously, `spawn_module_host` would unconditionally insert the new
module into the controller state, and not remove it if the lifecycle
hooks (`init_database` / `update_database`) returned an error.

This would mean that the module code was replaced with the new one, even
if it should be rejected because the schema was not updated or the init
/ update reducer failed.

Fix this by starting the module, and later "committing" it to the
controller state in two phases.

* Add commentary about database mutations / transactionality
2024-02-29 18:32:21 +00:00
joshua-spacetime b19de57522 perf(831): Remove row_pk computation from query (#908)
* perf(831): Remove row_pk computation from query

Closes #831.

* perf(831): remove Op, use identical TableOp.

perf(831): remove unnecesary .into_iter().map_into().collect()

perf(831): cleanup evaluators and make them lazier

* nix PrimaryKey & UniqueValue

* add TableOp::{insert, delete}

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-02-29 17:04:04 +00:00
james gilles 00aa2eedb4 Adjust benchmarks yaml to run callgrind plus with better comments (#907) 2024-02-28 21:45:36 +00:00
Shubham Mishra f7b0e0431a acquire remove subscription lock in spawn_blocking (#903)
* acquire remove subscription lock in spawn_blocking

* nit

Signed-off-by: Shubham Mishra <shubham@clockworklabs.io>

---------

Signed-off-by: Shubham Mishra <shubham@clockworklabs.io>
2024-02-28 20:47:40 +00:00
joshua-spacetime b2b8993e8e perf(832): Remove redundant row deduplication in subscriptions (#863)
* perf(832): Remove redundant row deduplication in subscriptions

Closes #832.

The database already operates under set semantics,
so unless multiple queries return rows from the same table,
deduplication of the result set is not necessary.

* Rip out all deduplication

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2024-02-28 19:51:18 +00:00
Phoebe Goldman efde86d981 Remove row_pk from client API; hash rows not row_ids on client (#840)
* Remove `row_pk` from client API; hash rows not row_ids on client

This commit removes the `row_pk` field from `message TableRowOperation` in the client API.
This is the beginning of addressing issue #831.

This has several implications for clients:
- Because we no longer have a stable content-addressed ID for each row,
  the client is responsible for hashing rows itself.
- This means that generated types must be `Hash + Eq`.
- This means that generated types must use `sats::F32` or `sats::F64`
  rather than `f32` or `f64`,
  as the former are `Eq + Hash` while the latter are not.
  (Aside: it's stupid that Rust floats are not `Eq + Ord + Hash`,
   since IEEE-754 defines a total equality and total ordering on floats.)

Exposing `sats::F32` to users is ugly, but I can't think of a better design.

This commit also makes some minor formatting changes to Rust codegen,
since it was emitting code that rustc warned about.

Still outstanding:

- [ ] Remove row_pk from the JSON API.
- [ ] Avoid computing row_pk in the subscription engine.
- [ ] Update other SDKs.
  - [ ] C#
  - [ ] TypeScript
  - [ ] Python

* Combine similar patterns

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>

* Remove `row_pk` from JSON messages

* fmt

* SDK: ClientCache keyed on BSATN bytes, not domain types

Per Ingvar's suggestion, this commit makes the client cache
be `HashMap<Vec<u8>, T>`, where the key is a BSATN byte-buffer
containing the serialized representation of the value.

This means that generated structs and enums don't need to be `Hash + Eq`.
The key upside here is that we can revert to using `f32`/`f64`
rather than `sats::F32`/`sats::F64`.

---------

Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-02-28 18:56:24 +00:00
Noa 558822e9ed Parallelize QuerySet::eval (#891)
* Parallelize QuerySet::eval

* Reduce number of arguments for make_actor
2024-02-28 06:14:30 +00:00
Tyler Cloutier 6e088a734f Added #[tracing::instrument(skip_all)] to add_subscriber 2024-02-27 18:17:08 -08:00
Phoebe Goldman d24ead52c6 VM: Wrap Header in Arc to avoid cloning (#897) 2024-02-27 18:26:38 +00:00
joshua-spacetime 1904008ffc refactor(890): Improve magic constant for index join selection (#895)
Closes #890.

This changes the magic constant from 1000 to 3000 rows,
which means if the indexed table in an index join has 3000 rows or less,
we make it the probe table instead.
2024-02-27 17:40:57 +00:00
Ingvar Stepanyan f63723a845 C#: reuse Consume helper (#704) 2024-02-27 11:25:36 +00:00
Tyler Cloutier 488d1355ac Revert "Run initial subscriptions evals on rayon (#888)" (#894)
This reverts commit 0ef145d435.
2024-02-27 02:08:52 +00:00
Noa 0ef145d435 Run initial subscriptions evals on rayon (#888) 2024-02-26 21:14:13 +00:00
Shubham Mishra 28868647cb serialise disconnect logic (#886)
* serialise disconnect logic

* Keep the ModuleHost::disconnect_client method

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2024-02-26 20:37:51 +00:00