Commit Graph

5918 Commits

Author SHA1 Message Date
Jussi Saurio
24219d2eb2 Merge 'Minor refactoring of btree' from meteorgan
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1917
2025-07-09 19:13:39 +03:00
Pekka Enberg
159710d1c9 Merge 'core: Fix resolve_function() error messages' from Pekka Enberg
We need to return the original function name, not normalized one to be
compatible with SQLite.
Spotted by SQLite TCL tests.

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

Closes #2017
2025-07-09 17:12:58 +03:00
meteorgan
0001348158 Minor refactoring of btree 2025-07-09 22:01:54 +08:00
Pekka Enberg
3f10427f52 core: Fix resolve_function() error messages
We need to return the original function name, not normalized one to be
compatible with SQLite.

Spotted by SQLite TCL tests.
2025-07-09 15:30:57 +03:00
Pekka Enberg
91fff1d2b3 Merge 'bindings/python: Start transaction implicitly in execute()' from Pekka Enberg
We need to start transaction implicitly in execute() for DML statements
to make sure first transaction is actually started.
Fixes #2002

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

Closes #2013
2025-07-09 14:34:02 +03:00
Jussi Saurio
1113e34c47 Merge 'VDBE: fix op_insert re-entrancy' from Jussi Saurio
when updating last_insert_rowid we call `return_if_io!(cursor.rowid())`
which yields IO on large records. this causes `op_insert` to insert and
overwrite the same row many times. we need a state machine to ensure
that the insertion only happens once and the reading of `rowid` can
independently yield IO without causing a re-insert.
to reproduce this bad behavior:
```sql
create table t(x);
insert into t values (randomblob(1024*1024));
```

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #2000
2025-07-09 14:31:21 +03:00
Jussi Saurio
c9a6c289e0 clippy 2025-07-09 14:26:43 +03:00
Jussi Saurio
38650eee0e VDBE: fix op_insert re-entrancy
when updating last_insert_rowid we call return_if_io!(cursor.rowid())
which yields IO on large records. this causes op_insert to insert and
overwrite the same row many times. we need a state machine to ensure
that the insertion only happens once and the reading of rowid can
independently yield IO without causing a re-insert.
2025-07-09 14:26:40 +03:00
Jussi Saurio
11d4489740 Merge 'sqlite3_ondisk: generalize left-child-pointer reading function to both index/table btrees' from Jussi Saurio
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #2015
2025-07-09 14:24:08 +03:00
Jussi Saurio
12a9f86779 Merge 'VDBE: fix op_idx_insert re-entrancy' from Jussi Saurio
Separates cursor.key_exists_in_index() into a state machine. The problem
with the main branch implementation is this:
`return_if_io!(seek)`
`return_if_io!(cursor.record())`
The latter may yield on IO and cause the seek to start over, causing an
infinite loop. With an explicit state machine we can control and prevent
this.

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #2011
2025-07-09 14:21:13 +03:00
Pekka Enberg
d1a775e445 Merge 'sim: post summary to slack' from Jussi Saurio
Closes #2016
2025-07-09 13:47:52 +03:00
Jussi Saurio
85ef8dd2e6 sim: post summary to slack 2025-07-09 13:30:42 +03:00
Pekka Enberg
6b4dda8b9b Merge 'bindings/javascript: Improve error handling compatibility with better-sqlite3' from Mikaël Francoeur
This PR brings the error handling of the js bindings one step closer to
better-sqlite3. There is still some work left for the error handling to
be 100% compatible.
This is my first non-trivial Rust PR, so if you have any comments that
can help me improve, please leave them on the PR.
-----
as part of https://github.com/tursodatabase/turso/issues/1900

Reviewed-by: Diego Reis (@el-yawd)

Closes #2009
2025-07-09 12:16:28 +03:00
Jussi Saurio
c752058a97 VDBE: introduce state machine for op_idx_insert for more granular IO control
Separates cursor.key_exists_in_index() into a state machine. The problem with
the main branch implementation is this:

`return_if_io!(seek)`
`return_if_io!(cursor.record())`

The latter may yield on IO and cause the seek to start over, causing an infinite
loop. With an explicit state machine we can control and prevent this.
2025-07-09 11:43:18 +03:00
Jussi Saurio
c13b2d5d90 sqlite3_ondisk: generalize left-child-pointer reading function to both index/table btrees 2025-07-09 11:07:42 +03:00
Pekka Enberg
5216e67d53 bindings/python: Start transaction implicitly in execute()
We need to start transaction implicitly in execute() for DML statements
to make sure first transaction is actually started.

Fixes #2002
2025-07-09 10:59:52 +03:00
Jussi Saurio
6faa07505c Merge 'uv run ruff format && uv run ruff check --fix' from Jussi Saurio
Closes #2012
2025-07-09 10:50:56 +03:00
Jussi Saurio
b1d51aadc5 Merge 'stress clippy' from Jussi Saurio
Closes #2014
2025-07-09 10:50:43 +03:00
Jussi Saurio
1bda8bb47a stress clippy 2025-07-09 10:41:18 +03:00
Pekka Enberg
a1ab0f12ea stress: Make error reporting less verbose by default 2025-07-09 10:18:23 +03:00
Jussi Saurio
f312227825 uv run ruff format && uv run ruff check --fix 2025-07-09 10:06:29 +03:00
Pekka Enberg
3e898cceb9 Merge 'Synchronize WAL checkpointing' from Pere Diaz Bou
Closes #2007
2025-07-09 09:40:26 +03:00
Pekka Enberg
943793a571 Turso 0.1.2-pre.1 2025-07-09 09:27:31 +03:00
Pekka Enberg
cf47097f45 Turso v0.1.2-pre.1 2025-07-09 09:27:25 +03:00
Pekka Enberg
1e9fd7d5ed Add scripts/gen-changelog.py 2025-07-09 09:27:09 +03:00
Pere Diaz Bou
f7465f665d add checkpoint lock to wal 2025-07-08 17:53:04 +02:00
Pekka Enberg
d0a80c6acd Merge 'Support except operator for Compound select ' from meteorgan
Closes: #1574

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

Closes #1858
2025-07-08 18:48:36 +03:00
Mikaël Francoeur
2a691f5044 make some errors compatible with better-sqlite3 2025-07-08 11:36:23 -04:00
meteorgan
99e0cf0603 add a constant MINIMUM_CELL_SIZE 2025-07-08 22:57:20 +08:00
meteorgan
04575456a9 fix Minimum cell size must not be less than 4 2025-07-08 22:57:20 +08:00
meteorgan
3065416bb2 cargo fmt 2025-07-08 22:57:20 +08:00
meteorgan
08be906bb1 return early if index is not found in op_idx_delete 2025-07-08 22:57:20 +08:00
meteorgan
829e44c539 fix test data 2025-07-08 22:57:20 +08:00
meteorgan
f44d818400 cargo fmt 2025-07-08 22:57:20 +08:00
meteorgan
6768f073c8 add tests for except operator 2025-07-08 22:57:20 +08:00
meteorgan
c6ef4898b0 fix: IdxDelete shouldn't raise error if P5 == 0 2025-07-08 22:57:20 +08:00
meteorgan
4a516ab414 Support except operator for compound select 2025-07-08 22:57:20 +08:00
Pekka Enberg
7c4bb3d4b9 Merge 'vdbe: fix compilation' from Pere Diaz Bou
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #2008
2025-07-08 17:55:59 +03:00
Pekka Enberg
b895381ae6 Revert "Merge 'Reachable assertions in Antithesis Python Test for better logging' from Pedro Muniz"
This reverts commit dbbc3f5190, reversing
changes made to 1cd5a49705. We're missing
some mandatory parameters, causing these to fail under Antithesis.
2025-07-08 17:51:12 +03:00
Pere Diaz Bou
511b80a062 do not assert connection is closed and return error on api 2025-07-08 16:47:03 +02:00
Pere Diaz Bou
232beddf62 vdbe: fix compilation 2025-07-08 16:15:29 +02:00
Pekka Enberg
ddbbddfbc3 Merge 'bindings/python: close connection only when reference count is one' from Pere Diaz Bou
Due to how `execute` is implemented, it returns a `Connection` clone
which internally shares a turso_core::Connection with every other
Connection. Since `execute` returns `Connection` and immediatly it is
dropped, it will close connection, checkpoint and leave database in
weird state.
Let's make sure we don't keep using a connection after it was dropped.
In case of executing a query that was closed we will try to rollback and
return early.

Closes #2006
2025-07-08 17:12:00 +03:00
Pere Diaz Bou
ef41c19542 assert is not closed already 2025-07-08 15:58:11 +02:00
Pere Diaz Bou
5319af8fd8 set closed to cell 2025-07-08 15:55:50 +02:00
Pekka Enberg
7ca84ee5b0 Merge 'parser: use YYSTACKDEPTH' from Lâm Hoàng Phúc
sqlite uses [fixed-size](https://github.com/sqlite/sqlite/blob/7fc6e6a27
26e650d3b82c6d3683bdbdc10e02467/tool/lempar.c#L238) array for `yystack`
and grow stack if needed. Let replace `vec` with `smallvec` in rust
version.
after:
```sh
sqlparser-rs parsing benchmark/sqlparser::select
                        time:   [564.19 ns 565.63 ns 567.18 ns]
                        change: [-11.514% -11.288% -11.067%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
sqlparser-rs parsing benchmark/sqlparser::with_select
                        time:   [1.9812 µs 1.9861 µs 1.9914 µs]
                        change: [-7.5226% -7.3080% -7.0858%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild

```

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

Closes #1999
2025-07-08 16:20:51 +03:00
Pekka Enberg
6fd03c5bb0 Merge 'CI: remove duplicate fuzz run' from Jussi Saurio
Closes #2003
2025-07-08 16:20:46 +03:00
Pere Diaz Bou
8909e198ae set closed flag for connection to detect force zombies
Let's make sure we don't keep using a connection after it was dropped.
In case of executing a query that was closed we will try to rollback and
return early.
2025-07-08 15:19:20 +02:00
Pere Diaz Bou
91107d364a only close connection in case of reference count is 1
Due to how `execute` is implemented, it returns a `Connection` clone
which internally shares a turso_core::Connection with every other
Connection. Since `execute` returns `Connection` and immediatly it is
dropped, it will close connection, checkpoint and leave database in
weird state.
2025-07-08 15:19:20 +02:00
Jussi Saurio
ee1ed1a6e6 Merge 'btree: fix incorrect comparison implementation in key_exists_in_index()' from Jussi Saurio
1. current implementation did not use the custom PartialOrd
implementation for RefValue
2. current implementation did not take collation into account
I don't have a test for this in this PR but it fixes an issue related to
#1757
EDIT:
Okay, it appears the first commit cannot be merged by itself because
since it fixes the incorrect comparison logic, now our UNION tests fail
due to UNIQUE constraint violation (since we are now correctly detecting
duplicates). I have introduced a workaround for this in https://github.c
om/tursodatabase/turso/pull/2001/commits/cb8a576501702cf91713c7f76520501
77318c49c
So, in effect, this PR:
Closes #1757
But, I will make better fixes in #1988 later.

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #2001
2025-07-08 16:03:34 +03:00
Jussi Saurio
6d6ab7480b revert running with release so that debug assertions will trigger in fuzz runs 2025-07-08 15:04:17 +03:00