Commit Graph

4178 Commits

Author SHA1 Message Date
pedrocarlo
56905fc340 refactor checkpoint in pager 2025-08-13 10:24:55 +03:00
pedrocarlo
a7f5912e7d adjust wal checkpoint to return completions 2025-08-13 10:24:55 +03:00
pedrocarlo
10ad43d9e0 sync should return completion 2025-08-13 10:24:55 +03:00
pedrocarlo
a7873d8907 remove write counters from Wal impls 2025-08-13 10:24:55 +03:00
pedrocarlo
494fdb828b buuble completions in pager 2025-08-13 10:24:55 +03:00
pedrocarlo
ccc22863c6 remove return_if_locked and return_if_locked_maybe_load 2025-08-13 10:24:55 +03:00
pedrocarlo
f95625a06c bubble completions in btree 2025-08-13 10:24:55 +03:00
pedrocarlo
82b75330bc adjust types.rs util.rs view.rs and mvcc to bubble io 2025-08-13 10:24:55 +03:00
pedrocarlo
2e68296107 create IOCompletions 2025-08-13 10:24:55 +03:00
Jussi Saurio
43628e2a9a Merge 'IO Cleanups to use and ' from Pedro Muniz
Depends on #2512 .
This is an attempt to remove all the noise from my IO completions
refactor into separate PRs

Closes #2566
2025-08-13 10:24:15 +03:00
Levy A.
6a37916b49 fix: rename indexed columns 2025-08-13 08:55:17 +03:00
Levy A.
45d959635c fix: check if index exists with the same name 2025-08-13 08:55:17 +03:00
Jussi Saurio
2a4404cd13 Merge 'move our dbsp-based views to materialized views' from Glauber Costa
We will implement normal SQLite-style view-as-an-alias for
compatibility, and will call our incremental views materialized views.

Closes #2571
2025-08-13 08:53:30 +03:00
Jussi Saurio
3e8a5b92ae Merge 'turso-sync: support checkpoint' from Nikita Sivukhin
remote protocol can require client to perform checkpoint of the WAL.
This PR supports that need in the sync-engine implementation

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

Closes #2565
2025-08-13 08:49:31 +03:00
pedrocarlo
85e86d427b cleanups - use io.block in many functions and return_if_io 2025-08-13 08:32:38 +03:00
Jussi Saurio
73a2851f0b Merge 'More State machines' from Pedro Muniz
Adds more state machines and does some minor adjustments in some other
functions like `commit_tx` and `execute`.

Closes #2512
2025-08-13 08:31:05 +03:00
Preston Thorpe
a0f70f04f2 Merge 'Rename page -> slot for arenas + buffer pool' from Preston Thorpe
No semantic changes here, just name changing for to prevent confusion as
@sivukhin pointed out.

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #2564
2025-08-12 16:03:00 -04:00
Glauber Costa
770f86e490 move our dbsp-based views to materialized views
We will implement normal SQLite-style view-as-an-alias for
compatibility, and will call our incremental views materialized views.
2025-08-12 14:19:17 -05:00
Nikita Sivukhin
1ac3d632ca support checkpoint from remote 2025-08-12 19:53:04 +04:00
PThorpe92
5a4c2a6ce9 Rename page -> slot for arenas + buffer pool 2025-08-12 11:36:49 -04:00
pedrocarlo
217c9061e8 advance commit_tx state machine in mvcc tests 2025-08-12 12:28:35 -03:00
pedrocarlo
e94f1f9f14 refactor move_to functions to return IO on start 2025-08-12 12:28:35 -03:00
pedrocarlo
4010dc8f32 state machine for insert 2025-08-12 12:28:35 -03:00
pedrocarlo
78a89f0fd3 execute should create an Statement 2025-08-12 12:28:35 -03:00
pedrocarlo
10cadd4037 do not use StepResult for commit_txn 2025-08-12 12:28:35 -03:00
pedrocarlo
9ab07f59ad adjust mvcc state transitions 2025-08-12 12:28:35 -03:00
pedrocarlo
fc5492bf2c state machine for op_row_id 2025-08-12 12:28:35 -03:00
pedrocarlo
1221f65d10 state machine for op_column 2025-08-12 12:28:35 -03:00
pedrocarlo
fe0e4bcbb7 state machine for seek_end 2025-08-12 12:28:35 -03:00
pedrocarlo
fc05518192 refactor continue_payload_overflow_with_offset 2025-08-12 12:28:34 -03:00
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
Nikita Sivukhin
d66d6d0220 add few comments 2025-08-12 18:41:30 +04: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
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
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
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
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