Commit graph

199 commits

Author SHA1 Message Date
Jussi Saurio
18f6e1a350 Update tests for BusySnapshot error
- Handle "snapshot is stale" in fuzz tests as retriable error
- Test that stale snapshot returns BusySnapshot, not Busy
2025-12-21 18:37:47 +02:00
pedrocarlo
eaadaee5c3 refactor more of the core tester to use helpers 2025-12-19 17:20:46 -03:00
pedrocarlo
e986247890 convert sqlite.rs + core tester to use helpers 2025-12-19 17:20:46 -03:00
Pekka Enberg
edd45ff7b8 Improve MVCC DX by dropping --experimental-mvcc flag
The DX is right now pretty terrible:

```
penberg@vonneumann turso % cargo run -- hello.db
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/tursodb hello.db`
Turso v0.4.0-pre.18
Enter ".help" for usage hints.
Did you know that Turso supports live materialized views? Type .manual materialized-views to learn more.
This software is in BETA, use caution with production data and ensure you have backups.
turso> PRAGMA journal_mode = 'experimental_mvcc';
  × Invalid argument supplied: MVCC is not enabled. Enable it with `--experimental-mvcc` flag in the CLI or by setting the MVCC option in `DatabaseOpts`

turso>
```

To add insult to the injury, many SDKs don't even have a way to enable
MVCC via database options. Therefore, let's remove the flag altogether.
2025-12-19 12:59:42 +02:00
Jussi Saurio
c282c24d94
Merge 'clean up core tester to use conn.execute and conn.exec_rows for parsing correctly the expected values from select queries' from Pedro Muniz
## Description
The PR title. `exec_rows` also does validation of outputs automatically
which is good practice for testing
<!--
Please include a summary of the changes and the related issue.
-->
## Motivation and context
Better typing and don't have to constantly match on `turso_core::Value`
<!--
Please include relevant motivation and context.
Link relevant issues here.
-->
## AI Disclosure
Ai did most of the migration
<!--
Please disclose if any LLM's were used in the creation of this PR and to
what extent,
to help maintainers properly review.
-->

Closes #4192
2025-12-18 09:22:45 +02:00
Pekka Enberg
98308415b4 core: Don't rollback transaction when schema updated
When the SchemaUpdated error occurs during statement execution, don't
roll back the transaction, but instead re-prepare the statement.

Spotted by Whopper.
2025-12-15 13:49:21 +02:00
PThorpe92
12601af1e1
increase lantency check for flaky test in test_read_path.rs 2025-12-12 13:49:56 -05:00
pedrocarlo
60ab032e3a clean up core tester to use conn.execute instead of limbo_exec_rows and use conn.exec_rows for parsing correctly the expected values from select queries 2025-12-12 12:36:48 -03:00
pedrocarlo
c207eddd3f remove unused TempDatabase argument requirement for limbo_exec_rows 2025-12-10 15:21:03 -03:00
Jussi Saurio
64dba96c60
Merge 'initialize global header on bootstrap' from Pedro Muniz
On bootstrap just store the header but not flush it to disk. Only try to
flush it when we start an MVCC transaction. Also applied fix in
`OpenDup` where we should not wrap an ephemeral table with an MvCursor

Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #4151
2025-12-10 19:04:23 +02:00
Jussi Saurio
0d35366f5d
Merge 'Fix CTE scope propagation for compound SELECTs' from Martin Mauch
CTEs now work correctly when combined with UNION, UNION ALL, INTERSECT,
and EXCEPT.
**Before:**
```sql
WITH t AS (SELECT 1 as x) SELECT * FROM t UNION ALL SELECT 2 as x
-- Error: Parse error: no such table: t
```
**After:**
```sql
WITH t AS (SELECT 1 as x) SELECT * FROM t UNION ALL SELECT 2 as x
-- Works correctly, returns rows (1) and (2)
```

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

Closes #4123
2025-12-10 19:04:03 +02:00
pedrocarlo
d09b48c0e6 test page1 init 2025-12-10 12:53:25 -03:00
Nikita Sivukhin
9acf541e28 add compatibility test for multiple-columns unique constraint 2025-12-10 01:46:25 +04:00
Martin Mauch
3dc8fed204 Fix CTE scope propagation for compound SELECTs 2025-12-09 13:09:55 +01:00
Nikita Sivukhin
997a07cac9 add test with concurrent commit/rollback and insert stmt 2025-12-08 16:34:07 +04:00
Jussi Saurio
826ca4d44d chore: remove experimental_indexes feature flags 2025-12-08 13:00:37 +02: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
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
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
Nikita Sivukhin
b3380bc398 treat parameters as "constant" within a query 2025-11-12 02:30:15 +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
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
22fe9452ac remove unnecessary parameter from integration tests 2025-10-27 15:16:12 +04:00
Nikita Sivukhin
299533b7b6 hide custom modules syntax behind --experimental-custom-modules flag 2025-10-27 12:29:05 +04:00
Sumit Patel
7f8f1bc074 Update the write_varint method to use an encoded buffer of size 9 instead of 10.
The SQLite varint specification states that the varint is guaranteed to be a maximum of 9 bytes, but our version of write_varint initializes a buffer of 10 bytes. Changing the size to match the specification.
2025-10-25 16:53:59 +05:30
Jussi Saurio
2b73260dd9 Handle cases where DB grows or shrinks due to savepoint rollback 2025-10-22 23:40:45 +03:00
Jussi Saurio
e9bfb57065 Fix incorrectly implemented test
Test started executing another statement when previous statement
returned IO the last time and didn't run to completion
2025-10-22 23:40:45 +03:00
Jussi Saurio
1dcfd3d068 fix stale test: constraint errors do not roll back tx anymore 2025-10-22 23:40:45 +03:00
Jussi Saurio
bebe230b05 Regression test: deferred FK violations are checked before commit 2025-10-20 13:59:37 +03:00
Jussi Saurio
56d5702176 Fix: rolling back tx should set autocommit to true
Rolling back a transaction should result in `connection.auto_commit` being set
back to true.

Added a regression test for this where a UNIQUE constraint violation rolls back
the transaction and trying to COMMIT will fail.

Currently, our default conflict resolution strategy is ROLLBACK,
which ends the transaction. In SQLite, the default is ABORT, which rolls back
the current statement but allows the transaction to continue.

We should migrate to default ABORT once we support subtransactions.
2025-10-16 12:05:53 +03:00
Jussi Saurio
2baea154b0 clippy 2025-10-13 14:11:18 +03:00
Jussi Saurio
3669437482 Add vibecoded tests for ColumnUsedMask 2025-10-13 14:03:34 +03:00
Jussi Saurio
e055ed9a8d Allow arbitrarily many columns in a table
Use roaring bitmaps because ColumnUsedMask is likely to be
sparsely populated.
2025-10-13 13:30:26 +03:00