Commit Graph

5105 Commits

Author SHA1 Message Date
Pere Diaz Bou
4cc88ee2bb core/mvcc/logical-log: rename Insert and Delete -> InsertRow and DeleteRow in LogRecordType 2025-09-22 13:21:54 +02:00
Pere Diaz Bou
db326affc6 core/mvcc/logical-log: rename LogRowType to LogRecordType 2025-09-22 13:19:02 +02:00
Pere Diaz Bou
e22a3893d5 core/mvcc/logical-log: remove column_count from insert row type 2025-09-22 13:18:17 +02:00
Pere Diaz Bou
4c959e760b core/mvcc/logical-log: add rows size field for transaction format 2025-09-22 13:15:07 +02:00
Pere Diaz Bou
2cd1562966 core/mvcc/logical-log: add format for transaction fields and marker end 2025-09-22 13:06:11 +02:00
Pere Diaz Bou
6fc1bed187 core/mvcc/logical-log: add format for logical log header 2025-09-22 13:00:52 +02:00
Pere Diaz Bou
36a728d984 core/mvcc/logical-log: add format for row types 2025-09-22 12:43:54 +02:00
Pekka Enberg
37866e74e5 Merge 'core/io: Ensure callbacks are invoked once' from Pedro Muniz
Add a `Once` object to uphold this property. We cannot use the OnceLock
to dictate this, because if we set the OnceLock before actually calling
the callback, there is a moment in time where we will have an incorrect
transient state. This change ensures we atomically call the callback and
then set the OnceLock
Should fix #3217
Closes #3217

Closes #3237
2025-09-22 11:44:39 +03:00
Pekka Enberg
0144ea8059 Merge 'Support UNION queries in DBSP-based Materialized Views' from Glauber Costa
UNION queries, while useful on their own, are a cornerstone of recursive
CTEs.
This PR implements:
* the merge operator, required to merge both sides of a union query.
* the circuitry necessary to issue the Merge operator.
* extraction of tables mentioned in union and CTE expressions, so we can
correctly populate tables that contain them.

Closes #3234
2025-09-22 11:33:19 +03:00
Pekka Enberg
19849c7895 Merge 'DBSP: Return a parse error for a non-equality join' from Glauber Costa
We currently don't handle non equality, but end up just returning a
bogus result. Let's parse error.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3232
2025-09-22 11:32:43 +03:00
Pekka Enberg
6280cfc59d Merge branch 'main' into sync-improvements 2025-09-22 07:35:39 +03:00
Pekka Enberg
dae72a7418 Merge 'Remove some unnecessary unsafe impls' from Pedro Muniz
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3236
2025-09-22 07:33:50 +03:00
Glauber Costa
2627ad44de support union statements in the DBSP circuit compiler 2025-09-21 21:00:27 -03:00
Glauber Costa
b419db489a Implement the DBSP merge operator
The Merge operator is a stateless operator that merges two deltas.
There are two modes: Distinct, where we merge together values that
are the same, and All, where we preserve all values. We use the rowid of
the hashable row to guarantee that: In Distinct mode, the rowid is set
to 0 in both sides. If they values are the same, they will hash to the
same thing. For All, the rowids are different.

The merge operator is used for the UNION statement, which is a
cornerstone of Recursive CTEs.
2025-09-21 21:00:27 -03:00
Glauber Costa
9f54f60d45 make sure that complex select statements are captured by MV populate
The population code extracts table information from the select statement
so it can populate the materialized view. But the code, as written
today, is naive. It doesn't capture table information correctly if there
is more than one select statement (such in the case of a union query).
2025-09-21 21:00:27 -03:00
pedrocarlo
ffeb26b24a only ever call callbacks once 2025-09-21 14:36:18 -03:00
pedrocarlo
e5dfc942b1 remove some unnecessary unsafe impls 2025-09-21 13:29:59 -03:00
Glauber Costa
13260349b0 Return a parse error for a non-equality join
We currently don't handle non equality, but end up just returning a
bogus result. Let's parse error.
2025-09-20 20:35:10 -03:00
Nikita Sivukhin
c63c820bb7 add busy_timeout pragma 2025-09-19 16:48:12 +04:00
Preston Thorpe
6b273af7e9 Merge 'translate/optimize: centralize AST/expr traversal' from Preston Thorpe
Previously we were rewriting/traversing the AST in a couple different
places, each of these added kinda ad-hoc as we needed them. This
attempts to do the binding of column references as well as the rewriting
of anonymous `Expr::Variable` -> `__param_N` that we use to maintain the
order of bound variables, also normalizes the Qualified Name's.
Also we previously weren't accepting Variable (or at least they wouldn't
work) in places like `LIMIT ? OFFSET ?`, which this PR adds.
I kinda want to keep refactoring translation a bit, and try to break
plan building up into more easy-to-digest chunks.. but I will resist the
urge right now as it's definitely not high priority pre-beta

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3210
2025-09-19 08:03:39 -04:00
Preston Thorpe
20493441e0 Merge 'prevent alter table with materialized views' from Glauber Costa
I don't want to even think about the complexity involved in making sure
that materialized views are still sane after the base table(s) are
altered.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3223
2025-09-19 08:01:58 -04:00
Pekka Enberg
9dda5a6263 Merge 'bugfix: clear reserved space for a reused page' from Avinash Sajjanshetty
fixes #3184

Closes #3198
2025-09-19 14:16:24 +03:00
Glauber Costa
8300d0390e prevent alter table with materialized views
I don't want to even think about the complexity involved in making sure
that materialized views are still sane after the base table(s) are
altered.
2025-09-19 05:59:46 -05:00
Pekka Enberg
2307cf03be Merge 'core/mvcc: Wrap LogicalLog in RwLock' from Pekka Enberg
Closes #3215
2025-09-19 13:40:40 +03:00
Pekka Enberg
69d4745aa0 Merge 'Support JOINs in DBSP materialized views' from Glauber Costa
This PR introduces the final major operator: the JOIN operator.
Many things need to be fixed before we can properly support them, and we
handle those. In particular, JOINs always generate qualified column
statements, but we were not handling them correctly at all in the
operators. Not a problem for linear circuits, but fatal for JOINs.
The operator.rs file also becomes incredibly complex with not one, but
two stateful operator. So it is now broken apart.

Closes #3207
2025-09-19 13:40:21 +03:00
Jussi Saurio
c5ebb0ef63 Merge 'mvcc: remove unused code related to is_logical_log()' from Jussi Saurio
is always logical log

Closes #3220
2025-09-19 13:31:34 +03:00
Jussi Saurio
ba7ae50eff mvcc: remove unused code related to is_logical_log()
is always logical log
2025-09-19 12:55:27 +03:00
Avinash Sajjanshetty
d5295fb45c Put the unused variable behind a flag as intended 2025-09-19 14:55:02 +05:30
Nikita Sivukhin
b106220743 main thread in browser can't execute parking - so we use parking lot in spin-lock style for that target 2025-09-19 13:21:00 +04:00
PThorpe92
e1ed12b284 rm claude comment 2025-09-19 05:20:20 -04:00
Glauber Costa
f2f7f817e4 populate all tables in IncrementalView
For joins to work, we have to populate all referenced tables when we
create the view.
2025-09-19 03:59:28 -05:00
Glauber Costa
e5a106d8d6 enable joins in IncrementalView 2025-09-19 03:59:28 -05:00
Glauber Costa
832a4d7034 generate projection nodes inside filter clauses
We are currently not able to properly compute things like WHERE a+b=2.
Let's generate a projection node inside a filter when needed.
2025-09-19 03:59:28 -05:00
Glauber Costa
627f61aa81 support column comparisons in the filter operator
We currently only support column / literal comparisons in the filter
operator. But with JOINs, comparisons are usually against two columns.

Do the work to support it.
2025-09-19 03:59:28 -05:00
Glauber Costa
47097fbec6 Add tests for project operator working with ambiguous columns
Unlike the other operators, project works just fine with ambiguous
columsn, because it works with compiled expressions. We don't need to
patch it, but let's make sure it keeps working by writing a test.
2025-09-19 03:59:28 -05:00
Glauber Costa
e80dd8e5e1 move the filter operator to accept indexes instead of names
We already did similarly for the AggregateOperator: for joins
you can have the same column name in many tables. And passing schema
information to the operator is a layering violation (the operator may be
operating on the result of a previous node, and at that point there is
no more "schema"). Therefore we pass indexes into the column set the
operator has.

The FilterOperator has a complication: we are using it to generate the
SQL for the populate statement, and that needs column names. However,
we should *not* be using the FilterOperator for that, and that is a
relic from the time where we had operator information directly inside
the IncrementalView.

To enable moving the FilterOperator to index-based, we rework that code.
For joins, we'll need to populate many tables anyway, so we take the
time to do that work here.
2025-09-19 03:59:28 -05:00
Glauber Costa
f149b40e75 Implement JOINs in the DBSP circuit
This PR improves the DBSP circuit so that it handles the JOIN operator.
The JOIN operator exposes a weakness of our current model: we usually
pass a list of columns between operators, and find the right column by
name when needed.

But with JOINs, many tables can have the same columns. The operators
will then find the wrong column (same name, different table), and
produce incorrect results.

To fix this, we must do two things:
1) Change the Logical Plan. It needs to track table provenance.
2) Fix the aggregators: it needs to operate on indexes, not names.

For the aggregators, note that table provenance is the wrong
abstraction. The aggregator is likely working with a logical table that
is the result of previous nodes in the circuit. So we just need to be
able to tell it which index in the column array it should use.
2025-09-19 03:59:28 -05:00
Glauber Costa
9f3d119a5a move hashable row tests to dbsp.rs
The operator.rs file was so huge, that we didn't even notice there was a
test block in the middle of the file that was testing things that were
long moved to dbsp.rs (the HashableRow). Move the tests there now.
2025-09-19 03:59:28 -05:00
Glauber Costa
e2f0e372a1 move the join operator to its own file.
The code is becoming impossible to reason about with everything in
operator.rs
2025-09-19 03:59:28 -05:00
Glauber Costa
aa8fcdbe54 move the aggregate operator to its own file.
The code is becoming impossible to reason about with everything in
operator.rs
2025-09-19 03:59:24 -05:00
Glauber Costa
7178d8d31c move the project operator to its own file.
The code is becoming impossible to reason about with everything in
operator.rs
2025-09-19 03:57:11 -05:00
Glauber Costa
ee914fc543 move the filter operator to its own file.
The code is becoming impossible to reason about with everything in
operator.rs
2025-09-19 03:57:11 -05:00
Glauber Costa
9747d6c6b6 move the input operator to its own file.
The code is becoming impossible to reason about with everything in
operator.rs
2025-09-19 03:57:11 -05:00
Glauber Costa
6be5eb74d9 Implement the Join Operator
The join operator is also a stateful operator. It keeps the input deltas
stored in the state, for both the left and right branches of the join.

JOINs extract a join key, which is the values that were used in the
join's equality statement. That key is now our zset_id, and it points
to a collection of rows.
2025-09-19 03:57:11 -05:00
Glauber Costa
2e7a45559b add joins to the logical plan 2025-09-19 03:57:11 -05:00
Glauber Costa
5b4a6e5c2d view: catch all tables mentioned, instead of just one.
Ahead of the implementation of JOINs, we need to evolve the
IncrementalView, which currently only accepts a single base table,
to keep a list of tables mentioned in the statement.
2025-09-19 03:57:11 -05:00
Glauber Costa
0b3317d449 extract columns from all tables in case of joins.
Our code for view needs to extract the list of columns used in the view.
We currently extract only from "the base table", but once we have joins,
we need a more complex structure, that keeps the mapping of
(tables, columns).

This actually affects both views and materialized views: for views, the
queries with joins work just fine, because views are just aliases for
a query. But the list of columns returned by pragma table_info on the
view is incorrect. We add a test to make sure it is fixed.

For materialized views, we add extensive tests to make sure that the
columns are extracted correctly.
2025-09-19 03:57:11 -05:00
Jussi Saurio
8555d81a62 mvcc: keep existing begin timestamp when upgrading mv tx to exclusive 2025-09-19 09:18:20 +03:00
Jussi Saurio
c289ab90bc mvcc: fix trying to end pager tx in rollback 2025-09-19 09:18:20 +03:00
Jussi Saurio
ed06c7c423 mvcc: fix hang when non-concurrent tx holds write lock 2025-09-19 09:18:20 +03:00