Commit graph

446 commits

Author SHA1 Message Date
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
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
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
pedrocarlo
a3acec58df clippy 2025-11-19 23:42:46 -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
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
Nikita Sivukhin
7294ef347f fix tests 2025-11-06 17:45:12 +04:00
Nikita Sivukhin
68a4c90446 fix fmt and test 2025-11-05 20:53:34 +04:00
Nikita Sivukhin
a64aef780d Merge branch 'main' into toy-index-improvements 2025-11-05 20:48:16 +04:00
RS2007
60cbc6d8ea migrating from_uri to database opts 2025-11-02 16:28:22 +05:30
Pekka Enberg
913b7ac600 core: Disable autovacuum by default
People have discovered various bugs in autovacuum so let's disable it by
default for now.
2025-11-02 12:09:21 +02:00
Nikita Sivukhin
47b4e7e376 fix clippy 2025-10-31 15:02:37 +04:00
Nikita Sivukhin
714400b299 add approximate search 2025-10-31 14:50:16 +04:00
Nikita Sivukhin
20919212f9 fix clippy 2025-10-31 14:30:07 +04:00
Nikita Sivukhin
49c1cf63b9 slightly adjust test 2025-10-31 14:22:55 +04:00
Nikita Sivukhin
29101a4b17 fix test 2025-10-29 22:49:29 +04:00
Nikita Sivukhin
c8be79ca94 cargo fmt 2025-10-29 15:15:45 +04:00
Nikita Sivukhin
35c323730c add test to reproduce the bug with cached cursors for statement in between of different runs
thread 'query_processing::test_read_path::test_stmt_reset' panicked at core/storage/sqlite3_ondisk.rs:754:9:
assertion failed: self.page_type() == PageType::TableLeaf
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test query_processing::test_read_path::test_stmt_reset ... FAILED
2025-10-29 15:13:00 +04:00
Nikita Sivukhin
e7cab016d4 fix tests 2025-10-28 11:27:35 +04:00
Nikita Sivukhin
6f62621b5e adjust test more 2025-10-28 11:27:35 +04:00