Commit Graph

3134 Commits

Author SHA1 Message Date
Pekka Enberg
6e79a11dc7 Merge 'bindings/dart initial implementation' from Andika Tanuwijaya
re-upload

Closes #1911
2025-07-04 10:43:19 +03:00
Pekka Enberg
97ea4f1a80 Merge 'add libsql_disable_wal_checkpoint' from Pedro Muniz
Closes #1894

Closes #1920
2025-07-04 10:04:00 +03:00
Krishna Vishal
19d949521a Add a threshold to clip large page cache values to 0. This prevents
panic at runtime.
2025-07-04 10:24:10 +05:30
pedrocarlo
56d87cb916 move disable behavior to connection instead of checkpoint 2025-07-03 12:05:53 -03:00
pedrocarlo
db005c81a0 add option to disable wal checkpoint 2025-07-03 12:04:17 -03:00
Pekka Enberg
90e035b6b0 Merge 'Rollback schema support' from Pere Diaz Bou
Fixes #1890
Once rollback was implement we quickly saw that it lacked support for
schema changes so we had to re-estructure things a bit.
## Example of failure:
```bash
turso> begin;
turso> create table t(x);
turso> rollback;
turso> pragma integrity_check;
thread 'main' panicked at core/storage/sqlite3_ondisk.rs:386:36:
called `Result::unwrap()` on an `Err` value: Corrupt("Invalid page type: 83")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
This happened because it thought table `t` existed because we didn't
rollback that schema.
## Changes:
* The most important change: now every connection has a private copy of
schema. On write txn commit we update a global schema shared between
connections in order for new connections to get updated version from
there. In case of rollback, we simply change connection's schema to
previous version. This change allowed us to remove locks for schema
private copy and keeping schema changes locally in case of concurrency.
 Sqlite does things differently, they lazily parse schema in case of
outdated schema, this many schema changes to trigger reading schema from
db file which is slow. If we are able to keep local copy in memory, even
when if we add multiprocessing, it will speed up schema reloading by a
bunch.
* `schema_cookie` is now update for every schema change
* `Insn::ParseSchema` had a nasty bug where it would commit all the
changes made in a query that changed a schema, we fixed that by setting
`auto_commit` to `false` before parsing schema, and setting it back to
previous value once schema is parsed.

Closes #1928
2025-07-03 14:18:00 +03:00
Pere Diaz Bou
5eca507867 fix type null spacing 2025-07-03 12:53:15 +02:00
Pere Diaz Bou
2cfd209e56 clippy 2025-07-03 12:40:08 +02:00
Pere Diaz Bou
151debcb63 fix to_sql btreetable 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
6b16950488 fmt 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
470fb8d23b rollabck translate remove querymode 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
cde7202981 Revert "Merge 'core: Disable ROLLBACK statement' from Pekka Enberg"
This reverts commit 8a13e4b02f, reversing
changes made to cc935f97cc.
2025-07-03 12:36:48 +02:00
Pere Diaz Bou
f37893eb8f set cookie for index operations 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
ba988685cf set cookie create virtual table 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
5d856499c4 move update schema global on commit and not on rollback txn 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
2414502268 parse schema set auto_commit false in nested query 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
d8658264d9 alter set cookie 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
c799396c3d rollback schema in connection 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
5b733663ab update schema in case it's outdated 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
65a7fe13cf remove lock from private schema copy 2025-07-03 12:36:48 +02:00
Pere Diaz Bou
abf1699dd2 set scheam version and update shared schema in txn 2025-07-03 12:36:48 +02:00
Pekka Enberg
fa442ecd6e core/storage: Switch to turso_assert in btree.rs
Let's help out Antithesis to find interesting bugs.
2025-07-03 13:25:13 +03:00
Pekka Enberg
c76625eb64 Merge 'fix: buffer pool is not thread safe problem' from KaguraMilet
This PR will close #1446. Buffer pool implementation should be thread
safe after this PR.

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

Closes #1910
2025-07-03 13:12:21 +03:00
Pekka Enberg
471d26a632 Merge 'Fix index update when INTEGER PRIMARY KEY (rowid alias)' from Adrian-Ryan Acala
When an `UPDATE` statement modifies a table's `INTEGER PRIMARY KEY`
(which acts as a `rowid` alias) alongside other indexed columns, the
index entries were incorrectly retaining the old `rowid`. This led to
stale index references, causing subsequent queries to return incorrect
results.
This change ensures that when the `rowid` alias is part of the `SET`
clause in an `UPDATE` statement, the new `rowid` value is used for
generating and updating index records. This guarantees that all index
entries correctly point to the updated row, resolving the data
inconsistency.
Fixes #1897

Closes #1916
2025-07-03 13:10:53 +03:00
KaguraMilet
f339e9c1ad fix integrity check error 2025-07-03 13:47:30 +08:00
KaguraMilet
562dd389db Merge branch 'tursodatabase:main' into buffer 2025-07-03 13:46:37 +08:00
Pekka Enberg
3bd5d4c732 core: Drop debugging code 2025-07-02 19:55:38 +03:00
Pekka Enberg
e8af5f1022 Merge 'from_uri was not passing mvcc and indexes flag to database creation for memory path' from Pedro Muniz
Closes #1932
2025-07-02 19:55:27 +03:00
pedrocarlo
191f732088 from_uri was not passing mvcc and indexes flag to database creation for memory path 2025-07-02 13:46:49 -03:00
Pekka Enberg
36b550cca4 Merge 'Fix boxed memory leaks' from Ihor Andrianov
We should recreate original box to drop it properly
Also made a fast path for hashing. When key div by 2. It should decrease
cpu cycles on hot path by x10 approximately
This thing is tricky, made a long running test that verify bug, put
#[ignore] on it to not slow down CI

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1873
2025-07-02 19:42:54 +03:00
Nikita Sivukhin
c9c5ef4e25 remote query_mode from ProgramBuilderOpts and from function arguments
- mode never changes and ProgramBuilder already created with proper mode set correctly
2025-07-02 13:24:12 +04:00
Pekka Enberg
e718cfef6b Merge 'Add opening new connection from a sqlite compatible URI, read-only connections' from Preston Thorpe
@penberg reminded me that this never got integrated :)

Closes #1908
2025-07-02 08:05:36 +03:00
Andika Tanuwijaya
135c81f2db ios support 2025-07-02 00:11:42 +07:00
Andika Tanuwijaya
4686592156 migrate dart binding to flutter plugin project 2025-07-02 00:04:42 +07:00
AdrianAcala
7ca902979d Fix: Correctly update indexes when INTEGER PRIMARY KEY (rowid alias) changes (Issue #1897)
When an `UPDATE` statement modifies a table's `INTEGER PRIMARY KEY` (which acts as a `rowid` alias) alongside other indexed columns, the index entries were incorrectly retaining the old `rowid`. This led to stale index references, causing subsequent queries to return incorrect results.

This change ensures that when the `rowid` alias is part of the `SET` clause in an `UPDATE` statement, the new `rowid` value is used for generating and updating index records. This guarantees that all index entries correctly point to the updated row, resolving the data inconsistency.
2025-07-01 16:03:27 +00:00
Ihor Andrianov
564bb28dea rewrite test to make fix verifiable 2025-07-01 17:27:58 +03:00
Ihor Andrianov
68e638e955 fix second occurance 2025-07-01 17:27:58 +03:00
Ihor Andrianov
647183938f fix sub with below 0 in tests 2025-07-01 17:27:58 +03:00
Ihor Andrianov
56b1fcf3b3 remove unused imports 2025-07-01 17:27:58 +03:00
Ihor Andrianov
41a11afe7c leaking box memory 2025-07-01 17:27:47 +03:00
KaguraMilet
aca08238d8 fix buffer pool is not thread safe problem 2025-07-01 16:06:55 +08:00
PThorpe92
bbee10ba2c Add mvcc and index config to connection open api 2025-06-30 22:04:56 -04:00
PThorpe92
2e967b778b Prevent writes to db file in the VDBE if we are in readonly mode 2025-06-30 22:04:56 -04:00
PThorpe92
8f141e934a Add readonly option to db connection and add method to open new connection via URI 2025-06-30 22:03:51 -04:00
Levy A.
25927d91d8 cargo fmt 2025-06-30 14:37:51 -03:00
Levy A.
ffd6844b5b refactor: remove PseudoTable from Table
the only reason for `PseudoTable` to exist, is to provide column
information for `PseudoCursor` creation. this should not be part of the
schema.
2025-06-30 14:31:58 -03:00
Levy A.
3907b387b3 cargo fix 2025-06-30 14:01:47 -03:00
Levy A.
afc55b27f0 refactor: remove unnecessary column definitions for PseudoTable
the only information that matters in the amount of column
2025-06-30 13:54:29 -03:00
Pekka Enberg
2542cb2d03 core: Disable ROLLBACK statement
There's bad interaction with schema changes and `ROLLBACK`:

https://github.com/tursodatabase/turso/issues/1890

Disable the statement for now to avoid people hitting the issue.
2025-06-30 17:30:01 +03:00
Pekka Enberg
51edab7032 Merge 'WAL record db_size frame on commit last frame' from Pere Diaz Bou
`db_size` is `>0` in case of last frame written of a transaction. This
is necessary as we need to know -- while recovering wal contents -- that
we have read a transaction fully instead of treating every frame as its
own transaction.

Closes #1866
2025-06-30 13:46:40 +03:00