Commit Graph

7489 Commits

Author SHA1 Message Date
pedrocarlo
81fbf8cb4b balance_non_root validation logic should be done in the next state 2025-08-12 12:28:34 -03:00
Pekka Enberg
0285fddd85 Merge 'Fix max_frame determination and comments in WAL checkpointing' from Preston Thorpe
in #2521, I messed up and introduced improper calculation of the current
checkpoint's max safe frame (mostly due to incorrect comments that I had
left on the method).
The confusion partially stems from our lack of Busy handling at the
moment, but essentially when determining the max safe frame for all
readers, for passive mode we cannot simply `break` out of the loop when
we find a reader with a lower read mark than we have, because _another_
reader might have an even _lower_ read mark, and we could proceed with
the first mark < shared_max.
And for !passive modes, we still attempt to backfill with the same lower
frame, we just return `Busy` at the end, after backfilling what we can
(we just don't reset the log for restart/truncate).
Most of the changes in this PR is just the renaming the fields of
Checkpoint Result, because the names were confusing

Closes #2560
2025-08-12 18:24:59 +03:00
Pekka Enberg
97ad901d96 Merge 'simple README with warning' from Nikita Sivukhin
Closes #2562
2025-08-12 18:24:53 +03:00
Pekka Enberg
2e79333de4 Merge 'turso-sync: fix schema bug' from Nikita Sivukhin
This PR fixes few issues in turso-sync-engine implementation:
1. One step of `pull` implementation works like this:
   a. Start write WAL session
   b. Revert local changes in WAL
   c. Replay WAL frames from remote DB
   d. Replay WAL frames produced by local changes applied to the remote
DB copy (`synced`)
My initial thinking was that by executing step (d) we will get the same
schema as before (with same schema cookie) and everything will be fine.
With more deep thinking we can see that it's not fine - as after step
(d) tables created locally can change their root pages (if they were
created locally, for example) - and DB will have "broken" schema
2. Sync engine execute few SQL statements and do not run them to
completion - which basically created "orphaned" locks
In order to fix (1) I decided to introduce another `conn_raw_api`
extension which allows to read and write schema cookie directly in the
transaction. So, the process described above adds step (e) which set
schema cookie to the value strictly greater than the value before.
In order to fix (2) I just fixed all places where statement were dropped
before running to completion.
These fixes are merged together because I explored them by fixing one
new test: `test_sync_single_db_many_pulls_big_payloads`

Closes #2561
2025-08-12 18:24:46 +03:00
Nikita Sivukhin
02bb891104 add npm badge 2025-08-12 18:55:39 +04:00
Nikita Sivukhin
35b51d8302 simple README with warning 2025-08-12 18:52:58 +04:00
Nikita Sivukhin
d66d6d0220 add few comments 2025-08-12 18:41:30 +04:00
Nikita Sivukhin
bf2a01866c fix clippy 2025-08-12 18:33:12 +04:00
Nikita Sivukhin
d3a27ee311 fix sync engine 2025-08-12 18:30:16 +04:00
Pekka Enberg
269b23ece5 Merge branch 'main' of https://github.com/tursodatabase/limbo 2025-08-12 17:08:30 +03:00
Pekka Enberg
5a65617602 Turso 0.1.4-pre.7 2025-08-12 17:01:47 +03:00
Pekka Enberg
2e326f5a79 Merge 'bindings/javascript: Add async connect() function' from Pekka Enberg
Let's make the API symmetric with libSQL and serverless drivers.

Closes #2557
2025-08-12 17:01:19 +03:00
Nikita Sivukhin
1d8ed9aa55 add methods for read/write schema cookie 2025-08-12 17:29:56 +04:00
PThorpe92
c3b536957f Fix max_frame determination and comments in WAL checkpointing 2025-08-12 08:57:35 -04:00
Pekka Enberg
b82d850f7a Merge 'Reset interrupt count each time a new line is entered in CLI' from
Resolves issue #1833.
**Before:**
<img width="581" height="92" alt="Screenshot 2025-08-11 at 9 07 21 PM"
src="https://github.com/user-
attachments/assets/eff4c919-ad54-4379-bbee-28eb3e4a375f" />
**After:**
<img width="563" height="118" alt="Screenshot 2025-08-11 at 9 07 27 PM"
src="https://github.com/user-
attachments/assets/f99f84a0-f5d3-4d70-9e08-1c3871fddda3" />

Closes #2554
2025-08-12 11:50:03 +03:00
Pekka Enberg
3429e833f8 Merge 'Fix: Rename clickbench output file limbo/turso' from Henrik Ingo
Closes #2552
2025-08-12 11:40:55 +03:00
Pekka Enberg
96673a54a8 bindings/javascript: Add async connect() function
Let's make the API symmetric with libSQL and serverless drivers.
2025-08-12 11:39:59 +03:00
Pekka Enberg
1c6a3bacb9 testing/javascript: Fix libSQL connection setup
The API changed in libSQL to be async.
2025-08-12 11:33:54 +03:00
Jussi Saurio
0c9180426f Merge 'Direct schema mutation – add RenameColumn instruction' from Levy A.
<img width="934" height="511" alt="image" src="https://github.com/user-
attachments/assets/992e6c7e-5b4a-4cd2-9040-5d1f44ca55d0" />
<img width="973" height="261" alt="image" src="https://github.com/user-
attachments/assets/e179143a-92f3-427a-be9a-280ce6a739f6" />

Closes #2546
2025-08-12 10:19:31 +03:00
Jussi Saurio
9b5e61eacd Merge 'Reprepare fix on write statement' from Pedro Muniz
We have to update the Transaction State before checking for the Schema
Cookie so that we can rollback the transaction later on correctly.
Closes #2535

Closes #2549
2025-08-12 10:18:12 +03:00
Jussi Saurio
03373afe1f Merge 'core/wal: Minor checkpointing cleanups and optimizations' from Preston Thorpe
Small contribution to my current work on making checkpointing efficient.
We hold a write lock, and especially here on main there is no reason to
mark the pages as dirty in the cache, so we can do away with that
Vec<u64> and just track whether it's `Done`

Closes #2545
2025-08-12 10:16:51 +03:00
Pekka Enberg
db54c953bd Merge 'Implement Aggregations for DBSP views' from Glauber Costa
```
turso> create table t(a, b);
turso> insert into t(a,b) values (2,2), (3,3);
turso> insert into t(a,b) values (6,6), (7,7);
turso> insert into t(a,b) values (6,6), (7,7);
turso> create view tt as select b, sum(a) from t where b > 2 group by b;
turso> select * from tt;
┌───┬─────────┐
│ b │ sum (a) │
├───┼─────────┤
│ 3 │       3 │
├───┼─────────┤
│ 6 │      12 │
├───┼─────────┤
│ 7 │      14 │
└───┴─────────┘
turso> insert into t(a,b) values (1,3);
turso> select * from tt;
┌───┬─────────┐
│ b │ sum (a) │
├───┼─────────┤
│ 3 │       4 │
├───┼─────────┤
│ 6 │      12 │
├───┼─────────┤
│ 7 │      14 │
└───┴─────────┘
turso>
```

Closes #2547
2025-08-12 09:52:22 +03:00
Pekka Enberg
5303622802 Merge 'perf/btree: optimize op_column' from Jussi Saurio
Mainly the performance impact here comes from removing some unnecessary
checks and inlining `read_integer_fast()` directly into `op_column()`,
but I also added some fiddly nano-optimizations for fun
On main, we are roughly 3.4x slower than sqlite on `SELECT * FROM users
LIMIT 100`, and here we are roughly 3.2x slower, which ain't much, but
it's honest work.
A more impactful optimization, but a much more annoying refactor, would
be #2304

Closes #2516
2025-08-12 09:51:38 +03:00
Pekka Enberg
104669b0c8 Merge 'stop silently ignoring unsupported features in incremental view where clauses' from Jussi Saurio
Closes #2543
2025-08-12 09:50:58 +03:00
Pekka Enberg
bfefa44632 Merge 'turso-sync: support updates and schema changes' from Nikita Sivukhin
Add support for schema changes and granular updates in the
`DatabaseTape` and turso-sync-engine
Now, schema changes made locally will be replicated to the remote too.
Also, `UPDATE`s made locally will touch only changed columns (before we
did `DELETE` + `INSERT` which can overwrite non-conflicting changes from
another device to the same row).
Note, that schema changes replication for now can be pretty dangerous,
as we can't extract proper schema at some moment in time from turso_cdc
and always use latest schema columns. This means that it's better to
avoid `ALTER TABLE ...` to be executed locally, but basic DDL like
`CREATE TABLE / CREATE INDEX / DROP TABLE / DROP INDEX` will work fine
(as columns only appear/disappear for schema in this case).

Closes #2540
2025-08-12 09:50:26 +03:00
Pekka Enberg
2fa501158c Merge 'turso-cdc: add updates column for cdc table' from Nikita Sivukhin
This PR adds new `updates` column to the CDC table. This column holds
updated fields of the row in the following format:
```
[C boolean values where true set for changed columns]
[C values with updates where NULL is set for not-changed columns]
```
For example:
```
turso> UPDATE t SET y = 'turso', q = 'db' WHERE rowid = 1;
turso> SELECT bin_record_json_object('["x","y","z","q","x","y","z","q"]', updates) as updates FROM turso_cdc;
┌──────────────────────────────────────────────────────────────────┐
│ updates                                                          │
├──────────────────────────────────────────────────────────────────┤
│ {"x":0,"y":1,"z":0,"q":1,"x":null,"y":"turso","z":null,"q":"db"} │
└──────────────────────────────────────────────────────────────────┘
```
Also, this column works differently for `ALTER TABLE` statements where
update value for `sql` will be equal to the original `ALTER TABLE`:
```
turso> ALTER TABLE t ADD COLUMN t;
turso> SELECT bin_record_json_object('["type","name","tbl_name","rootpage","sql","type","name","tbl_name","rootpage","sql"]', updates) as updates FROM turso_cdc WHERE rowid = 2;
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ updates                                                                                                                                           │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ {"type":0,"name":0,"tbl_name":0,"rootpage":0,"sql":1,"type":null,"name":null,"tbl_name":null,"rootpage":null,"sql":"ALTER TABLE t ADD COLUMN t;"} │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
This will help turso-db to implement logical replication which supports
both column-level updates and schema changes

Closes #2538
2025-08-12 09:50:16 +03:00
Pekka Enberg
1349c051f8 Merge 'Fix view processing in the VDBE' from Jussi Saurio
1. Introduce state machines to insert and delete to make sure IO is
handled properly
2. When `rowid` is changed in `UPDATE`, it is handled as a combination
of delete and insert, so `op_insert` doesn't need to update the
incremental view with the deleted old column since the preceding
`op_delete` instruction should already do it.

Closes #2542
2025-08-12 09:49:11 +03:00
rajajisai
5cc5b0bca1 Reset interrupt count each time a new line is entered in CLI 2025-08-11 21:16:43 -07:00
Henrik Ingo
c4cba8b195 Fix: Rename clickbench output file limbo/turso 2025-08-12 04:56:17 +03:00
Preston Thorpe
9a595d6ffa Merge 'Update PERF.md with mobibench instructions' from Preston Thorpe
Closes #2550
2025-08-11 19:56:56 -04:00
PThorpe92
4c876547f0 Add Mobibench to .gitignore 2025-08-11 19:56:26 -04:00
PThorpe92
d2df8bf1a3 Update PERF.md 2025-08-11 19:44:12 -04:00
pedrocarlo
cf416ed461 update transaction state before checking schema cookie 2025-08-11 20:23:35 -03:00
pedrocarlo
96a6bc5125 end_tx does not need schema_did_change variable 2025-08-11 18:59:11 -03:00
pedrocarlo
c456eff069 Add test_schema_reprepare_write 2025-08-11 18:56:53 -03:00
PThorpe92
c098a48924 Remove clear dirty from checkpoint state machine in sratch page 2025-08-11 16:40:05 -04:00
PThorpe92
688851c97a Take instead of clone vec of buffers in write_pages_vectored 2025-08-11 16:18:43 -04:00
Levy A.
665f10d71b feat: add RenameColumn instruction 2025-08-11 17:08:06 -03:00
Glauber Costa
333c5c435b unify populate
populate now has its own code path to apply changes to the view. It was
okay until now because all we do is filter. But now that we are also
applying aggregations, we'll end up with two disjoint code paths.

A better approach is to just apply the results of our select to the
delta set, and apply it.
2025-08-11 15:06:57 -05:00
Glauber Costa
27c22a64b3 views: implement aggregations
Hook up the AggregateOperator. Also wires up the tracker, allowing us to
verify how much work was done.
2025-08-11 15:06:57 -05:00
PThorpe92
e2896d2f95 Minor improvement in flush api 2025-08-11 16:01:41 -04:00
PThorpe92
1f554c2707 Cleanup some minor checkpointing issues 2025-08-11 15:40:36 -04:00
Jussi Saurio
909c096579 Merge 'docs: improve README initialization section clarity' from Braden Wong
Improves the clarity of the README's "Getting Started" → "Command Line"
section by adding explicit `$ tursodb` command example so users know
exactly what to type.

Closes #2534
2025-08-11 21:11:01 +03:00
Jussi Saurio
f598c86fa4 Merge 'Handle single, double and unquoted strings in values clause' from Mikaël Francoeur
I'm not sure how much this will clash with @TcMits's parser rewrite,
hopefully not too much. If it does and we eventually have to remove it,
at least we'll have two new regression tests.
Closes https://github.com/tursodatabase/turso/issues/2484

Closes #2499
2025-08-11 21:08:15 +03:00
Jussi Saurio
a7c1c8b7d4 Merge 'Use rusqlite 0.37 with bundled SQLite everywhere' from Jussi Saurio
Use the same rusqlite version in every crate and use a bundled up-to-
date sqlite version
(the impetus for this PR is still me trying to figure out why sqlite in
the insert benchmark doesn't seem to be fsyncing, even when instructed)

Closes #2507
2025-08-11 21:07:24 +03:00
Preston Thorpe
cb59877821 Merge 'Feat/pragma module list' from Lucas Forato
Implementation of the module_list pragma

Reviewed-by: Diego Reis (@el-yawd)
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2430
2025-08-11 13:54:24 -04:00
PThorpe92
4dbf69545e try_borrow.unwrap -> borrow 2025-08-11 13:54:00 -04:00
Jussi Saurio
7339b207e3 add assert 2025-08-11 19:25:25 +03:00
Jussi Saurio
28d6c2b673 fix flags again 2025-08-11 19:22:22 +03:00
Braden Wong
51d2824b6e fix: tursodb insteada of turso for shell command in README 2025-08-11 12:17:33 -04:00