Commit graph

486 commits

Author SHA1 Message Date
Preston Thorpe
c09c30746e
Merge 'guard subjournal access within single connection' from Nikita Sivukhin
Right now turso can panic with various asserts if 2 or more write
statements will be executed over single connection concurrently:
```
thread 'query_processing::test_write_path::api_misuse' panicked at core/storage/pager.rs:776:9:
subjournal offset should be 0
```
This PR adds explicit guard for subjournal access which will return
`Busy` for the operation internally and lead to wait condition for the
statement until subjournal ownership will be released and can be re-
acquired again.

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

Closes #4110
2025-12-05 13:14:07 -05:00
Preston Thorpe
e7c7f232b4
Merge 'testing/fuzz: Add new fuzzer for joins' from Preston Thorpe
needed for #4063 to merge, currently passing on main but just want to
lower the already huge diff

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

Closes #4103
2025-12-05 13:13:44 -05:00
Nikita Sivukhin
659ef7c079 fix clippy 2025-12-05 21:39:35 +04:00
Nikita Sivukhin
487854e6d6 guard subjournal access in order to prevent concurrent operations over it within same connection 2025-12-05 21:25:13 +04:00
PThorpe92
c9a6827011
Extract out join fuzzer to an additional test on indexed columns 2025-12-05 12:03:23 -05:00
Jussi Saurio
a90087bcf6 Enable compound_select_fuzz for mvcc because it works as a regression test for #4108 2025-12-05 17:19:05 +02:00
Nikita Sivukhin
d5f58de801 fix clippy 2025-12-05 15:29:17 +04:00
Nikita Sivukhin
e839eb499b make fuzzer to generate SELECT COUNT(*) OR SELECT * statements
- this is important for IN operation translation bug because in case of COUNT(*) there is constant assignment instruction right after last instruction translated from IN condition
2025-12-05 14:48:59 +04:00
Jussi Saurio
eb782ce2d4 fix/mvcc: seek() must seek from both mv store and btree
for example, upon opening an existing database, all the rows are in
the btree, so if we seek only from MV store, we won't find anything.
ergo: we must look from both the mv store and the btree. if we are
iterating forwards, the smallest of the two results is where we land,
and vice versa for backwards iteration.

initially this implementation used blocking IO but was refactored to
use state machines after the rest of the Cursor methods in the MVCC cursor
module were refactored to do that too.

---

this PR was initially almost entirely written using Claude Code + Opus 4.5,
but heavily manually cleaned up as the AI made the state machine refactor
far too complicated.
2025-12-05 11:53:16 +02:00
PThorpe92
16a1940d3a
Reduce iteration count in join fuzzer to 2000 2025-12-04 16:23:46 -05:00
PThorpe92
bf6038f0ba
Add join fuzzer for non-indexed columns 2025-12-04 16:19:19 -05:00
Jussi Saurio
3eccee731e Remove todo comment from test 2025-12-03 16:32:20 +02:00
Jussi Saurio
fd067912dc tests/fuzz/mvcc: enable table_index_mutation_fuzz for mvcc
special cases: do not use triggers or expression indexes for the
mvcc version of the test.
2025-12-03 16:28:53 +02:00
Jussi Saurio
3b412f9b02 mvcc: commit index rows and recover them from logical log
also adds tests
2025-12-02 11:38:05 +02:00
Jussi Saurio
ea905d276c
Merge 'Add #[turso_macros::test] to automatically create tests that can run MVCC with minimal code changes' from Pedro Muniz
- added procedural macro that creates Rust tests and with just a flag,
creates a new test that runs the same with MVCC enabled
- migrated almost all tests to use this new macro and added the mvcc
flag to the tests that were not failing
- added a `TempDatabase` builder to facilitate the proc_macro to
generate the correct database options

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

Closes #3991
2025-11-27 21:53:09 +02:00
Jussi Saurio
e5937de219 mvcc: reconstruct index rows on logical log recovery
index rows are not committed to the logical log, so we derive them
after recovery and insert them to the mv store.
2025-11-27 20:35:49 +02:00
PThorpe92
9223dfdbff
Add integration test to ensure covering expr index is used 2025-11-20 12:47:50 -05:00
PThorpe92
2688f8b9c3
Add tcl tests for expr indexes and collation 2025-11-20 12:47:49 -05:00
PThorpe92
b0ac042092
Add tests for using expr indexes in query plans for ORDER BY and WHERE predicates 2025-11-20 12:47:47 -05:00
PThorpe92
04629d4d7b
Add some expression indexes in our fuzz tests 2025-11-20 12:47:46 -05:00
pedrocarlo
2ef2b13278 pending byte page cannot run at the same time with mvcc test 2025-11-19 23:52:22 -03:00
pedrocarlo
a3acec58df clippy 2025-11-19 23:42:46 -03:00
pedrocarlo
963b37f6ee change fuzz test to use new test macros 2025-11-19 23:28:23 -03:00
pedrocarlo
8b2caab3cc change pragma test to use new test macros 2025-11-19 23:28:23 -03:00
pedrocarlo
5aed5147c9 change trigger test to use new test macros 2025-11-19 23:28:23 -03:00
pedrocarlo
c4653ae34c change functions to use new test macros 2025-11-19 23:28:23 -03:00
pedrocarlo
479048ee99 change index_methods to use new test macros 2025-11-19 23:28:23 -03:00
pedrocarlo
4a79d4f5d4 change encryption to use new test macros 2025-11-19 14:47:13 -03:00
pedrocarlo
3bc0499f97 change test_btree to use new test macros 2025-11-19 13:46:48 -03:00
pedrocarlo
789532688e change test_ddl to use new test macros 2025-11-19 13:30:35 -03:00
pedrocarlo
c58cd32eee change test_multi_thread to use new test macros 2025-11-19 13:30:05 -03:00
pedrocarlo
5301a042d9 change test_read_path to use new test macros 2025-11-19 13:30:05 -03:00
pedrocarlo
f3854c2db2 change test_transactions to use new test macros 2025-11-19 12:28:37 -03:00
pedrocarlo
39ffa76c28 change test_write_path to use new test macros 2025-11-19 12:08:48 -03:00
pedrocarlo
463ca00004 migrate test cases to use the macro 2025-11-19 12:08:18 -03:00
pedrocarlo
0ffda31549 add init_sql arg to proc macro 2025-11-19 12:08:18 -03:00
pedrocarlo
91e1fc45fa create temp database builder to facilitate passing options to proc macro 2025-11-19 12:08:18 -03:00
pedrocarlo
1e85706d54 pass the fn arg type to the macro closure to avoid errors 2025-11-19 11:49:53 -03:00
pedrocarlo
237ce5b601 enhance proc macro to detect the fn args and the return type with better spans 2025-11-19 11:49:53 -03:00
pedrocarlo
696bf2252c create a basic test proc macro that takes a db path and an mvcc flag 2025-11-19 11:49:53 -03:00
pedrocarlo
62f2720fa5 simplify TempDatabase creation 2025-11-19 11:49:53 -03:00
Jussi Saurio
5d9a0b15f8 Handle qualified column references in triggers wrt ALTER TABLE 2025-11-19 14:29:33 +02:00
Jussi Saurio
745cdc3aa2 Align trigger sql rewrite behavior with sqlite
SQLite doesn't rewrite INSERT lists or WHEN clause, it instead
lets the trigger go "stale" and will cause runtime errors. This
may not be great behavior, but it's compatible...
2025-11-19 14:29:33 +02:00
Jussi Saurio
a0a1bd6637 Triggers: fix issues with ALTER TABLE
- Disallow DROP COLUMN on columns referenced in triggers
- Propagate RENAME COLUMN to trigger SQL definitions

DROP COLUMN is not allowed when the column is mentioned in a trigger
on the table the column is dropped from, eg:

```
turso> CREATE TABLE t(x,y);
turso> CREATE TRIGGER foo BEFORE INSERT ON t BEGIN INSERT INTO t VALUES (NEW.x); END;
turso> ALTER TABLE t DROP COLUMN x;
  × Parse error: cannot drop column "x": it is referenced in trigger foo
```

However, it is allowed if the trigger is on another table:

```
turso> CREATE TABLE t(x,y);
turso> CREATE TABLE u(x,y);
turso> CREATE TRIGGER bar BEFORE INSERT ON t BEGIN INSERT INTO u(y) VALUES (NEW.x); END;
turso> ALTER TABLE u DROP COLUMN y;
turso> INSERT INTO t VALUES (1,1);
  × Parse error: table u has no column named y
```

Nearly all of the code here is vibecoded. I first asked Cursor Composer to create
an initial implementation. Then, I asked it to try to discover edge cases using the
`turso` and `sqlite3` CLIs, and write tests+fixes for the edge cases found.

The code is a bit slop, but this isn't a particularly performance-critical use case
and it should solve most of the issues with RENAME and DROP COLUMN.
2025-11-19 14:29:33 +02:00
Jussi Saurio
e1dee4a072 triggers: add a lot of different kinds of tests 2025-11-18 15:19:01 +02:00
PThorpe92
0bc56d3f28
Sprinkle some OR REPLACE into INSERT statements in fuzzing 2025-11-17 08:23:16 -05:00
Jussi Saurio
65a7dd40b3
Merge 'Change Value::Text and ValueRef::Text to use Cow<'static, str> and &str to avoid allocations' from Pedro Muniz
When building text values, we could not pass ownership of newly created
strings, which meant a lot of the times we were double cloning strings,
one to transform, and one to build the Value

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

Closes #3932
2025-11-12 12:54:16 +02:00
Nikita Sivukhin
b3380bc398 treat parameters as "constant" within a query 2025-11-12 02:30:15 +04:00
pedrocarlo
1db13889e3 Change Value::Text to use a Cow<'static, str> instead of Vec<u8> 2025-11-11 16:11:46 -03:00
Pekka Enberg
a6593d109e
Merge 'Toy index improvements' from Nikita Sivukhin
Some checks failed
Python / macos-arm64 (aarch64) (push) Has been cancelled
Python / sdist (push) Has been cancelled
Rust / cargo-fmt-check (push) Has been cancelled
Rust Benchmarks+Nyrkiö / bench (push) Has been cancelled
Rust / test-sqlite (push) Has been cancelled
Build & publish @tursodatabase/database / db-bindings-aarch64-apple-darwin - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / db-bindings-aarch64-unknown-linux-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / db-bindings-wasm32-wasip1-threads - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Has been cancelled
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Has been cancelled
Rust / build-native (macos-latest) (push) Has been cancelled
Rust / build-native (windows-latest) (push) Has been cancelled
Rust / clippy (push) Has been cancelled
Rust / simulator (push) Has been cancelled
Rust / test-limbo (push) Has been cancelled
Rust Benchmarks+Nyrkiö / clickbench (push) Has been cancelled
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Has been cancelled
Rust Benchmarks+Nyrkiö / tpc-h (push) Has been cancelled
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Has been cancelled
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Has been cancelled
Python / test (push) Has been cancelled
Python / Release (push) Has been cancelled
Build & publish @tursodatabase/database / Publish (push) Has been cancelled
This PR implements more sophisticated algorithm in the toy vector sparse
index: now we enumerate components based on the frequency (in order to
check unpopular "features" first) and also estimate length threshold
which can give us better results compared with current top-k set.
Also, this PR adds optional `delta` parameter which can enable
approximate search which will return results with score not more than
`delta` away from the optimal.
In order to implement this index method - index code were slightly
adjusted in order to allow to store some non-key payload in the index
rows. So, now index can hold N columns where first K <= N columns will
be used as identity (before that K always was equal to N).

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

Closes #3862
2025-11-07 08:29:47 +02:00