Commit Graph

9264 Commits

Author SHA1 Message Date
pedrocarlo
2cd7c68c35 adjust property generation to not panic by always having some property to select from 2025-09-22 15:24:30 -03:00
pedrocarlo
7d1f23dd3a better diffing with similar crate 2025-09-22 15:24:30 -03:00
pedrocarlo
05034e1f9d instead of incrementing interaction counter, just substitue the current state 2025-09-22 15:24:30 -03:00
Jussi Saurio
1d4b301f05 Merge 'mvcc: simplify StateMachine' from Jussi Saurio
`TransitionResult::Continue` is an internal implementation detail that
tells an invocation of `StateMachine::step()` to continue looping, but
it is of no use to upstream callers.
For this reason, just return an IOResult from StateMachine::step() which
simplifies the result handling.

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #3248
2025-09-22 17:03:16 +03:00
Pekka Enberg
69b2e86c9c Merge 'Fix busy handler' from Lâm Hoàng Phúc
@penberg i think it fixed #3144, but i got locked database error
```sh
Running write throughput benchmark with 5 threads, 1000 batch size, 1000 iterations, mode: Legacy
Database created at: write_throughput_test.db
Thread error 0: SQL execution failure: `database is locked`
Thread 1: 1000000 inserts in 514.45s (1943.82 inserts/sec)
Error: SqlExecutionFailure("database is locked")
```

Closes #3147
2025-09-22 16:43:51 +03:00
Jussi Saurio
4af49ef98c mvcc: simplify StateMachine
TransitionResult is an internal implementation detail that tells
an invocation of StateMachine::step() to continue looping, but it
is of no use to other callers.

For this reason, just return an IOResult from StateMachine::step()
which simplifies the result handling.
2025-09-22 16:37:31 +03:00
Jussi Saurio
5498816d0b Merge 'mvcc: add blocking checkpoint lock' from Jussi Saurio
This PR does not implement MVCC checkpoint yet, just adds a lock for it.
MVCC checkpoints are always TRUNCATE, plus they block all other
transactions. This guarantees that never need to let transactions read
from the SQLite WAL.
In MVCC, the checkpoint procedure is roughly as follows:
- Take the blocking_checkpoint_lock
- Write everything in the logical log to the pager, and from there
commit to the SQLite WAL.
- Immediately TRUNCATE checkpoint the WAL into the database file.
- Release the blocking_checkpoint_lock.

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #3244
2025-09-22 16:16:26 +03:00
Preston Thorpe
44dc4c9636 Merge 'translate/emitter: Implement partial indexes' from Preston Thorpe
This PR adds support for partial indexes, e.g. `CREATE INDEX` with a
provided predicate
```sql
CREATE UNIQUE INDEX idx_expensive ON products(sku) where price > 100;
```
The PR does not yet implement support for using the partial indexes in
the optimizer.

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

Closes #3228
2025-09-22 09:09:54 -04:00
Pekka Enberg
972c01f6f7 Merge 'core: Wrap Pager::io_ctx in RwLock' from Pekka Enberg
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3246
2025-09-22 15:41:30 +03:00
Pekka Enberg
372daef656 core: Wrap Pager::io_ctx in RwLock 2025-09-22 15:00:29 +03:00
Pekka Enberg
2af98223ae Merge 'Enable checksum tests if checksum feature is on' from Kacper Kołodziej
These tests fail if checksum feature is turned off.

Closes #3242
2025-09-22 14:40:34 +03:00
Pekka Enberg
49f551e6c3 Merge 'Wrap Pager vacuum state in RwLock' from Pekka Enberg
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3239
2025-09-22 13:44:22 +03:00
Jussi Saurio
127bc471ff Merge 'Enhancement to Sim Snapshot isolation code' from Pedro Muniz
- Made the code around snapshot isolation more ergonomic with each
connections having its own transaction state. Also when shadowing, we
pass a ShadowTablesMut object that dynamically uses the committed tables
or the connection tables depending on the transaction state.
- added begin concurrent transaction before every property when mvcc is
enabled (this is just so we can have some mvcc code be tested using the
simulator under Begin Concurrent, I have not yet implemented the logic
to have concurrent transactions in the simulator)
- some small enhancements to shrinking
TODOs
- have proper logic to have concurrent transactions without WriteWrite
conflicts. This means when generating the plans we need to make sure
that we do not generate rows that will conflict with rows in other
transactions. This is slightly more powerful than what we do in the
fuzzer, as we just have `WriteWriteConflict` as an acceptable error
there. By baking this `NoConflict` approach to the simulator, we can
continuously test the what does not trigger a WriteWriteConflict and
snapshot isolation.

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

Closes #3226
2025-09-22 12:48:36 +03:00
Jussi Saurio
6a20735fe0 mvcc: add blocking checkpoint lock
MVCC checkpoints are always TRUNCATE, plus they block all other transactions.
This guarantees that never need to let transactions read from the SQLite WAL.

In MVCC, the checkpoint procedure is roughly as follows:
- Take the blocking_checkpoint_lock
- Write everything in the logical log to the pager, and from there commit to the SQLite WAL.
- Immediately TRUNCATE checkpoint the WAL into the database file.
- Release the blocking_checkpoint_lock.
2025-09-22 12:40:19 +03:00
TcMits
17c91c1fe2 resolve conflicts 2025-09-22 16:03:52 +07:00
Kacper Kołodziej
76f2e4e217 Enable checksum tests if checksum feature is on
These tests fail if checksum feature is turned off.
2025-09-22 10:46:49 +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
26f90257a6 Turso 0.2.0-pre.6 2025-09-22 11:44:21 +03:00
Pekka Enberg
979e2542af Merge branch 'main' of https://github.com/tursodatabase/limbo 2025-09-22 11:44:07 +03:00
Pekka Enberg
f4b0fb17f7 Turso 0.2.0-pre.5 2025-09-22 11:34:22 +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
390181c024 Merge 'Upgrade dist to 0.30.0' from Pekka Enberg
Closes #3241
2025-09-22 11:30:51 +03:00
Pekka Enberg
6f258b37d9 core/storage: Wrap Pager vacuum state in RwLock 2025-09-22 10:34:58 +03:00
Jussi Saurio
f1b0ffc053 clippy is angry about printing an empty string 2025-09-22 10:21:16 +03:00
Pekka Enberg
e5a3512f79 Upgrade dist to 0.30.0 2025-09-22 10:19:46 +03:00
Jussi Saurio
c0fc2ad234 fix optimizer tests 2025-09-22 10:18:03 +03:00
Jussi Saurio
eada24b508 Store in-memory index definitions most-recently-seen-first
This solves an issue where an INSERT statement conflicts with
multiple indices. In that case, sqlite iterates the linked list
`pTab->pIndex` in order and handles the first conflict encountered.
The newest parsed index is always added to the head of the list.

To be compatible with this behavior, we also need to put the most
recently parsed index definition first in our indexes list for a given
table.
2025-09-22 10:11:50 +03:00
Jussi Saurio
ef9f2f9a33 test/fuzz: add prints to get exact executed statements for debugging 2025-09-22 10:11:42 +03:00
Pekka Enberg
751261566e Fix Antithesis and simulator Dockerfiles 2025-09-22 10:02:01 +03:00
Pekka Enberg
f053b76518 core/storage: Move vacuum state machines to VacuumState 2025-09-22 09:37:40 +03:00
Pekka Enberg
fbad158213 Turso 0.2.0-pre.4 2025-09-22 09:15:55 +03:00
Pekka Enberg
18c41b0f5a Merge 'sqlite3: Fix compatibility test error by canonicalizing path' from Samuel Marks
Use canonical path to fix temp path on macOS ; rename to resolve binding
connascence. Fixes:
```
---- tests::test_sqlite3_db_filename stdout ----

thread 'tests::test_sqlite3_db_filename' (62061) panicked at sqlite3/tests/compat/mod.rs:1251:13:
assertion `left == right` failed
  left: "/private/var/folders/w5/21g61wls7ksd3z8cxrj41s1c0000gn/T/.tmpNcCUO2.db"
 right: "/var/folders/w5/21g61wls7ksd3z8cxrj41s1c0000gn/T/.tmpNcCUO2.db"
```

Closes #3227
2025-09-22 09:15:00 +03:00
Pekka Enberg
46297acb31 Merge 'Sync improvements' from Nikita Sivukhin
This PR improves sync and database bindings for browser
List of changes:
- For node and browser database now run on main thread and only IO work
offloaded to the worker (web worker in browser)
- Simple locks are implemented for database access externally in order
to guard access to the same connection (when request is executed async -
main thread can try to start another request concurrently)
- parking_lot in the Wal replaced by spin-wait (by invoking
`parking_lot.try_read/try_write`) for WASM target because browser can't
park main thread
- js sync reworked in order to support few engine options
(`longPollTimeoutMs`) and introduce external locking which properly
guards concurrent access of sync methods

Closes #3218
2025-09-22 09:14:30 +03:00
Pekka Enberg
6280cfc59d Merge branch 'main' into sync-improvements 2025-09-22 07:35:39 +03:00
Pekka Enberg
54176d4548 Merge 'Add encryption throughput test' from Avinash Sajjanshetty
```
cargo run --release -- -b 100 -i 100000 --read-ratio 75

cargo run --release -- -b 100 -i 100000 --read-ratio 75 --encryption
```
```
Total time: 629.51s

Transaction throughput: 158.85 txns/sec
Operation throughput: 15885.37 ops/sec
  - Read operations: 7500165 (7500165 found, 0 not found)
  - Read throughput: 11914.29 reads/sec
  - Write operations: 2499835
  - Write throughput: 3971.08 writes/sec
```
vs
```
Total time: 665.05s

Transaction throughput: 150.36 txns/sec
Operation throughput: 15036.47 ops/sec
  - Read operations: 7500165 (7500165 found, 0 not found)
  - Read throughput: 11277.60 reads/sec
  - Write operations: 2499835
  - Write throughput: 3758.87 writes/sec
```

Closes #3230
2025-09-22 07:34:29 +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
PThorpe92
7def22ef3c Add DO UPDATE SET case to partial index/upsert fuzzing 2025-09-21 14:47:59 -04:00
pedrocarlo
ffeb26b24a only ever call callbacks once 2025-09-21 14:36:18 -03:00
PThorpe92
4867999381 Add partial_index_mutation_and_upsert_fuzz test 2025-09-21 13:29:30 -04:00
PThorpe92
a1ca56620a Add SQLITE_CONSTRAINT_UNIQUE constraint to op_halt handling 2025-09-21 13:29:01 -04:00
PThorpe92
6fb4b03801 Fix UPSERT handling, properly rebuild indexes only based on what columns they touch 2025-09-21 13:28:36 -04:00
PThorpe92
0ea6e5714d Separate UPSERT behavior into preflight and commit state to prevent inserting idx before violating unique constraint 2025-09-21 13:27:50 -04:00
PThorpe92
e545e75e31 Emit Affinity instruction for unique index, and use no_constant_opt 2025-09-21 13:24:48 -04:00
PThorpe92
63177c42e4 Add SQLITE_CONSTRAINT_UNIQUE error constant 2025-09-21 13:22:31 -04:00
pedrocarlo
6e2b0c901e remove PanicGenerationContext and instead just pass the connection context directly 2025-09-21 14:16:46 -03:00
pedrocarlo
e5dfc942b1 remove some unnecessary unsafe impls 2025-09-21 13:29:59 -03:00