Commit Graph

7745 Commits

Author SHA1 Message Date
Preston Thorpe
7f8e181cda Merge 'Add documentation and rename functions' from Mikaël Francoeur
This PR adds documentation and renames some functions. Among other
things, I renamed everything that was still called `owned_value` to
either `db_value` or `value` (after
https://github.com/tursodatabase/turso/pull/1488).

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2619
2025-08-16 17:45:33 -04:00
Preston Thorpe
53c68bccab Merge 'Add io_yield macros to reduce boilerplate' from Preston Thorpe
```rust
io_yield_one!(c);

// instead of

return Ok(IOResult::IO(IOCompletions::Single(c))));
```

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

Closes #2630
2025-08-16 17:12:45 -04:00
PThorpe92
2c526c4c37 Add io_yield_x macros to reduce boilerplate 2025-08-16 16:14:00 -04:00
Pekka Enberg
5a167517e8 Merge 'Add --keep-files flag to allow for inspection of files for successful simulator runs ' from Preston Thorpe
Also fixes an issue where since the old Database wasn't `Drop`d, it
caused an issue with the static Registry ™️ that had broken
`--doublecheck` mode.

Closes #2623
2025-08-16 09:53:41 +03:00
Pekka Enberg
39fe7a0a32 Merge 'core/printf: support for the %i operand' from Luiz Gustavo
This continues the work for `printf` support from from tthe issue
https://github.com/tursodatabase/turso/issues/885.
This PR adds support for `%i` operands in the printf function. An
example of a command that works now and didn't before:
```sql
SELECT PRINTF("Decimals: %d %i", 200, 300);
```
This is Just an initial very simple contribution to get my feet wet and
learn the basics about the project and how contributions here work. I
intend to do something more meaningful in next contributions. Probably
will try to finish support for missing `printf` functionality also.

Closes #2615
2025-08-16 09:53:10 +03:00
Pekka Enberg
63c22c79cf Merge 'sync-engine: Use SQL over HTTP instead of WAL push' from Nikita Sivukhin
This PR switches from usage of WAL push to SQL over http calls.
As we have sequence of logical changes from CDC - we can just send SQL
statements to the remote. This will give us benefits of more smooth
concurrent usage of sync - because WAL push is very unfriendly in case
of concurrent usages.

Closes #2617
2025-08-16 09:51:15 +03:00
Preston Thorpe
cfad078087 Merge 'Add parser to Dockerfiles for cargo chef' from Jussi Saurio
antithesis and limbo-sim push fail because this is missing

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

Closes #2622
2025-08-15 18:02:25 -04:00
Preston Thorpe
97526ee4d1 Merge 'Add framework for testing extensions in TCL' from Piotr Rżysko
There is a distinction between tests that verify extension-specific
behavior and those that verify interactions between the database engine
and extensions. Previously, both types of tests were kept in
`extensions.py`. With this new framework, we can extract the latter type
of tests from `extensions.py` into TCL. This cleans up `extensions.py`
and enables compatibility testing with SQLite at no extra cost.
I’m currently working on supporting outer joins involving TVFs and
planning to add more tests that exercise the database’s handling of
virtual tables, so I decided to do this refactoring first.
In the future, we may consider moving extension-specific tests to TCL as
well, especially those that have counterparts in SQLite or sqlean.

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

Closes #2556
2025-08-15 17:58:21 -04:00
PThorpe92
2810b5d8a2 Add --keep-files flag and force Drop of database in simulator to prevent issues with the Registry 2025-08-15 17:54:40 -04:00
Mikaël Francoeur
2ee0132afe rename functions 2025-08-15 17:08:53 -04:00
Jussi Saurio
e4fb02b6e6 Add parser to Dockerfiles for cargo chef 2025-08-15 23:53:02 +03:00
Jussi Saurio
7a025c7c51 Merge 'Fix two issues in simulator' from Jussi Saurio
## 1. select equal number of columns per compound subselect in simulator
#2609 fixed compound selects incorrectly, introducing another bug: now
the sim can SELECT a different number of columns per subselect, which is
illegal. this PR forces the sim to select the same number of cols per
subselect.
Depends on #2614 , otherwise the sim constantly fails whenever it
decides to do a compound select with DISTINCT.
Closes #2611
## 2. introduce TableContext for the simulator to properly generate
predicates for Joins
The simulator has a construct called `JoinTable` which is really a
`JoinContext` that includes all the columns from the so-far joined
tables, so that the next table to be joined can refer to columns from
any of those tables. @pedrocarlo 's commit fixes an issue where
`JoinTable` would incorrectly generate predicates with empty table
names. Related: #2618

Closes #2616
2025-08-15 23:49:29 +03:00
pedrocarlo
2bc6edc3d4 introduce TableContext for the simulator to properly generate predicates for Joins 2025-08-15 23:44:00 +03:00
Jussi Saurio
3760d44c13 sim: force compound selects to have the same number of result columns 2025-08-15 23:43:38 +03:00
Jussi Saurio
c03517da40 Merge 'Fix distinct order by' from Jussi Saurio
Closes #2612
Two commits:
## Simplify ORDER BY sorter column remapping
In case an ORDER BY column exactly matches a result column in the
SELECT,
the insertion of the result column into the ORDER BY sorter can be
skipped
because it's already necessarily inserted as a sorting column.
For this reason we have a mapping to know what index a given result
column
has in the order by sorter.
This commit makes that mapping much simpler.
## Fix DISTINCT with ORDER BY
We had a bug where we were checking for duplicates in the DISTINCT
index based on both the result column count plus any ORDER BY columns
not present in the DISTINCT clause.
This is wrong, so fix it by only using the result columns for the
dedupe check.

Closes #2614
2025-08-15 23:43:29 +03:00
Piotr Rzysko
d1a91a63e6 Extract TVF-related tests to TCL
These tests verify interactions between the database engine and TVFs.
They happen to use generate_series, but they are not intended to test
the behavior of any specific extension. Tests that verify generate_series
specific behavior remain in extensions.py.
2025-08-15 21:06:30 +02:00
Piotr Rzysko
20ea079679 Add framework for testing extensions in TCL
There is a distinction between tests that verify extension-specific
behavior and tests that verify interactions between the database engine
and extensions. Previously, both types of tests were kept in extensions.py.
With this new framework, we can extract the latter type of tests from
extensions.py into TCL. This cleans up extensions.py and provides
compatibility testing with SQLite at no extra cost.

To demonstrate the framework’s usage, tests verifying the handling of
virtual tables were extracted to TCL.

In the future, we may consider moving extension-specific tests to TCL as
well, especially those that have counterparts in SQLite or sqlean.
2025-08-15 21:06:27 +02:00
Piotr Rzysko
116673c2e5 Unify how SQL is executed in TCL tests 2025-08-15 21:06:17 +02:00
Mikaël Francoeur
4a986080d2 add documentation 2025-08-15 14:59:37 -04:00
Nikita Sivukhin
b9a23f3067 fix clippy 2025-08-15 17:01:40 +04:00
Nikita Sivukhin
fef4e7e0e6 move tests from tursodb repo to turso-server repo 2025-08-15 16:59:53 +04:00
Nikita Sivukhin
979e7da633 use sql-over-http instead of WAL push 2025-08-15 16:59:43 +04:00
Jussi Saurio
d2cfe06aa5 Fix DISTINCT with ORDER BY
We had a bug where we were checking for duplicates in the DISTINCT
index based on both the result column count plus any ORDER BY columns
not present in the DISTINCT clause.

This is wrong, so fix it by only using the result columns for the
dedupe check.
2025-08-15 15:49:55 +03:00
luizgfc
e370b714c9 core/printf: support for the %i operand 2025-08-15 09:48:55 -03:00
Jussi Saurio
a99c8a8ca0 Simplify ORDER BY sorter column remapping
In case an ORDER BY column exactly matches a result column in the SELECT,
the insertion of the result column into the ORDER BY sorter can be skipped
because it's already necessarily inserted as a sorting column.

For this reason we have a mapping to know what index a given result column
has in the order by sorter.

This commit makes that mapping much simpler.
2025-08-15 15:48:41 +03:00
Pekka Enberg
c1c2b45141 core/vdbe: Drop excessive logging 2025-08-15 14:56:06 +03:00
Pekka Enberg
f47f0f6423 Merge 'Fix WAL initialization to last committed frame' from Nikita Sivukhin
Set in-memory WAL information according to last commited frame
- before that pages_in_frames, frame_cache and last_checksum was set to
the latest written (not commited!) frame in the WAL found on disk
Simple example to reproduce the data-loss:
```sh
n=$RANDOM
./target/debug/tursodb data-loss-$n.db 'create table t(x)';
strace -o /dev/null -e fault=pwrite64:error=EIO:when=5 ./target/debug/tursodb data-loss-$n.db 'insert into t values (randomblob(4 * 4096));'
./target/debug/tursodb data-loss-$n.db 'insert into t values (1);' 
./target/debug/tursodb data-loss-$n.db 'select x from t;'
```
The main bug which contributes to the data-loss was update of
`last_checksum` to the value from last frame read from WAL while
actually DB must use checksum of last **commited** frame. Due to this
bug, `insert` from third operation used checksum from last **written**
frame, but continued to append wal from the position after last
**committed** frame. So, fourth operation read WAL, detected checksum
mismatch and dropped all frames written by third operation.

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

Closes #2613
2025-08-15 14:54:16 +03:00
Pekka Enberg
bbc88e8a16 Merge 'Convert SQLite parser in Rust by hand ' from Lâm Hoàng Phúc
working on #2337

Closes #2381
2025-08-15 14:51:14 +03:00
TcMits
e90e154f51 fmt 2025-08-15 17:09:30 +07:00
TcMits
145300877b merge main 2025-08-15 17:07:21 +07:00
TcMits
4d91f19ab2 rebase 2025-08-15 17:05:28 +07:00
TcMits
fb5203ce45 make eat_assert faster 2025-08-15 16:45:20 +07:00
TcMits
9cec83f20b remove unused deps 2025-08-15 16:45:20 +07:00
TcMits
949bc97ced clippy again 2025-08-15 16:45:18 +07:00
TcMits
22f53d1fe6 clippy again 2025-08-15 16:45:18 +07:00
TcMits
1cafdc1f8e fmt 2025-08-15 16:45:18 +07:00
TcMits
f0bd4cca69 clippy 2025-08-15 16:45:18 +07:00
TcMits
3f19d2aa1a deps 2025-08-15 16:45:18 +07:00
TcMits
bbd96d263c finish REINDEX 2025-08-15 16:45:08 +07:00
Nikita Sivukhin
ac26e1cbe5 use DatabaseReplayGenerator in the DatabaseTape 2025-08-15 13:23:25 +04:00
Nikita Sivukhin
e6dafafccc extract stateless component for generting replay queries 2025-08-15 13:23:25 +04:00
Nikita Sivukhin
36106a2d6c parse bin record early 2025-08-15 13:23:25 +04:00
Nikita Sivukhin
71bbc36f61 adjust log message 2025-08-15 13:19:46 +04:00
Nikita Sivukhin
2361587d81 cargo fmt 2025-08-15 13:18:50 +04:00
Nikita Sivukhin
9b08f8c0f2 set in-memory WAL information according to last commited frame
- before that pages_in_frames, frame_cache and last_checksum was set to the latest written (not commited!) frame in the WAL found on disk
2025-08-15 13:13:33 +04:00
Nikita Sivukhin
6280d33b02 init tracing in CLI early
- now we miss logs from DB initialization phase
2025-08-15 13:11:38 +04:00
Jussi Saurio
a1401e43e6 Merge 'sim: add Property::TableHasExpectedContent' from Jussi Saurio
We are relying too much on the currently disabled `FaultyQuery` and
`FsyncNoWait` to assert the basic invariant of "the rows we have
inserted/updated/deleted in the database are still there", so adding
that as a separate `Property` here.

Closes #2610
2025-08-15 11:20:36 +03:00
Jussi Saurio
96072509f5 sim: add Property::TableHasExpectedContent 2025-08-15 11:16:31 +03:00
Jussi Saurio
4c76191fec fix/sim: fix incorrect implementation of compound select generation
Problem:

sim was generating compound selects like this:

- pick a random `table`
- create a random single SELECT
- create `n` random compound SELECTs (UNION ALL etc)

assign a WHERE clause that always has a condition based on `table`

This can result in e.g.

```
SELECT a FROM foo WHERE bar.x = 'baz'
```

Solution:

Don't base the WHERE clause on a table that might not be referenced
in the query.

Again, the only reason this wasn't caught before was because `FaultyQuery`
and `FsyncNoWait` are the only paths where this is actually tested with an
assertion, and those are both disabled
2025-08-15 10:48:42 +03:00
Pekka Enberg
e4f424f9e6 Merge 'Properly implement CLI command' from Preston Thorpe
Closes #2588
SQLite internally implements `.clone` by doing something like piping
`.dump` into a new connection to a database attached to the file you
want. This PR implements that by adding an `ApplyWriter` that implements
`std::fmt::Write`, and refactors our current `.dump` plumbing to work
with any `Write` interface, so we can `.dump` to stdout or `.dump` to a
new connection, therefore cloning the database.

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #2590
2025-08-15 10:44:57 +03:00