Commit Graph

7724 Commits

Author SHA1 Message Date
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
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
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
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
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
Pekka Enberg
a39105f9ce Merge 'Ensure we fsync the db file in all paths that we checkpoint' from Preston Thorpe
closes #2607

Closes #2608
2025-08-15 10:43:47 +03:00
Pekka Enberg
6105dd0ae6 Merge 'docs: add Claude Code MCP integration guide' from Braden Wong
Add comprehensive documentation for connecting Turso databases to Claude
Code using the built-in MCP management commands.
This PR addresses the need for easier integration between Turso and
Claude Code by providing clear, step-by-step instructions for users who
want to query their databases using natural language.

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

Closes #2606
2025-08-15 08:50:31 +03:00
PThorpe92
9ccf79111a Support non-utf8 blobs in .clone command 2025-08-14 21:31:14 -04:00
PThorpe92
2b289157d0 Properly quote sequence value 2025-08-14 21:31:14 -04:00
PThorpe92
7abf071128 Conditionally emit pragma foreign_keys=off when not .cloning 2025-08-14 21:31:14 -04:00
PThorpe92
6d7b660dd4 Adjust test for .clone method 2025-08-14 21:31:14 -04:00
PThorpe92
4a612c1586 Properly implement .clone method safely 2025-08-14 21:31:13 -04:00
PThorpe92
7c021c01f8 Remove copy_db method from connection 2025-08-14 21:31:13 -04:00
PThorpe92
cc2fed3297 Remove copy_to API from file IO trait 2025-08-14 21:31:13 -04:00
PThorpe92
285dcdd2c1 Prevent potential corruption from copying db file without holding proper locks 2025-08-14 21:31:13 -04:00
PThorpe92
3c088dda59 Update callsites of copy_to Database impl 2025-08-14 21:31:13 -04:00
PThorpe92
55f09a01c4 Update copy_to method in file trait to separate source and destination IO 2025-08-14 21:31:13 -04:00
PThorpe92
2ad479f413 dont forget other instance where db file is expected size 2025-08-14 19:56:23 -04:00
PThorpe92
9017acd622 Ensure we fsync the db file in all paths that we checkpoint 2025-08-14 19:23:00 -04:00
Braden Wong
95d9e99b3d docs: add Claude Code MCP integration guide
Add comprehensive documentation for connecting Turso databases to Claude Code using the built-in MCP management commands.

The new guide includes:
- Quick 3-step setup process
- Visual command breakdown with annotations
- Multiple usage examples (local, absolute paths, project-scoped)
- MCP server management commands
- Example natural language queries users can make

This makes it much easier for developers to integrate their Turso databases with Claude Code without manually configuring JSON files or understanding the underlying MCP protocol details.
2025-08-14 13:20:02 -07:00
Preston Thorpe
5cea0f572e Merge 'Revive async io extension PR' from Preston Thorpe
bringing #1127 back to life, except better because this doesn't add
Tokio as a dependency for extension lib just for tests.

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

Closes #2418
2025-08-14 16:10:09 -04:00
Preston Thorpe
64c83237b9 apply copilot review doc comment
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-14 16:09:25 -04:00
Preston Thorpe
e9d23e7fea apply copilot suggestion
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-14 16:08:55 -04:00
Preston Thorpe
c9888375fd Merge 'sim: reduce frequency of compound selects and complex joins' from Jussi Saurio
we spend a shitload of time doing very complex selects in the simulator,
and i'm not sure there has been a lot of gain from them. using up a lot
of the runtime of a simulator run on these can mask other issues.

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

Closes #2605
2025-08-14 16:03:55 -04:00
Preston Thorpe
a425c72ddc Merge 'Add assertion for expected write amount in writev callback' from Preston Thorpe
as @avinassh pointed out, if we have an error in a `writev` call, it
could go unnoticed and the checkpoint could proceed as expected after
not writing the expected total amt.

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

Closes #2601
2025-08-14 14:05:08 -04:00
Jussi Saurio
165f2aed23 make big joins even less likely 2025-08-14 19:35:16 +03:00