Commit Graph

6304 Commits

Author SHA1 Message Date
Jussi Saurio
4f0ef663e2 btree: add target cell tracking for EQ seeks 2025-07-18 13:48:23 +03:00
Jussi Saurio
2b23495943 btree: allow overwriting index interior cell 2025-07-18 13:48:23 +03:00
Jussi Saurio
e33ff667dc btree: use seek() when inserting -- replaces find_cell() 2025-07-18 13:48:23 +03:00
Jussi Saurio
9201030e67 Ephemeral UNION indexes don't need to be UNIQUE 2025-07-18 13:48:23 +03:00
Jussi Saurio
aeab89bd75 Fix parent page stack location after interior node replacement
Another fix extracted from running simulations on the #1988 branch.

When interior cell replacement happens as described in #2108,
we use the `cursor.prev()` method to locate the largest key in the
left subtree.

There was an error during backwards traversal in the `get_prev_record()`
method where the parent's cell index was set as `i32::MAX` but not properly
set to `cell_count + 1` (indicating that rightmost pointer has been visited).

The reason `i32::MAX` is used is that the cell count of the page is not
necessarily known at the time it is pushed to the stack.

This PR fixes the issue by setting the cell index of the parent properly
when visiting the rightmost child.
2025-07-18 13:30:01 +03:00
Jussi Saurio
b1ebc1c82f Merge 'sim: show seed in 'execute_interaction()' trace' from Jussi Saurio
This helps e.g. when you hit some infinite loop

Closes #2161
2025-07-18 12:27:48 +03:00
Jussi Saurio
086a269a65 Merge 'sim: change --disable-create-index flag to --enable-create-index (default false)' from Jussi Saurio
Closes #2160
2025-07-18 12:27:35 +03:00
Jussi Saurio
0af2443061 Merge 'sim: add order by to some queries' from Jussi Saurio
Closes #2159
2025-07-18 12:27:30 +03:00
Pekka Enberg
02f4bc39b3 Merge 'Reanimate MVCC' from Pekka Enberg
Bit-rot happened. Bring MVCC back from the dead.

Closes #2136
2025-07-18 11:22:49 +03:00
Jussi Saurio
687d126e25 sim: change --disable-create-index flag to --enable-create-index (default false) 2025-07-18 11:21:24 +03:00
Jussi Saurio
5b2d7315eb sim: show seed in 'execute_interaction()' trace 2025-07-18 11:21:04 +03:00
Jussi Saurio
9722aab8a1 clappy 2025-07-18 11:01:57 +03:00
Jussi Saurio
347a9152a6 Merge 'Replace verbose IO Completion methods with helpers' from Preston Thorpe
one of the last remnants of some original verbosity

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

Closes #2156
2025-07-18 10:52:17 +03:00
Jussi Saurio
bbd7f32d80 Merge 'Fix rollback for TxErrors' from Diego Reis
Fixes #2153.
Not so sure if SQLite doesn't rollback in more cases, we should
definitively check this out.

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

Closes #2154
2025-07-18 10:49:29 +03:00
Jussi Saurio
7e1755ac6f Merge 'Use pread and pwrite in run_once' from Ihor Andrianov
pread and pwrite is usually less instructions then seek and read. Also
added possibility for io to retry if AGAIN error happens. And made write
to wait for Event::writable

Reviewed-by: Preston Thorpe (@PThorpe92)
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #2010
2025-07-18 10:48:26 +03:00
Jussi Saurio
d67a9f03fd sim: add order by to some queries 2025-07-18 10:47:36 +03:00
Jussi Saurio
2be9ead3f7 Merge 'Core: Introduce external sorting' from Iaroslav Zeigerman
Closes #91
Replaces #1771 since the previous PR went stale and had too many
conflicts.
The maximum size of the in-memory buffer is determined by the settings
that configure the page-cache size.
In scope:
- Spill the in-memory buffer to a temporary file on disk if its size
exceeds the threshold
- When iterating over the sorter, the next record is picked using heap
populated from sorted chunk files
- Flushing the in-memory buffer and reading from chunk files occur
asynchronously.

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

Closes #2128
2025-07-18 10:44:56 +03:00
Iaroslav Zeigerman
28ff170e14 improve sorter settings in the fuzz test 2025-07-18 07:41:15 +02:00
Iaroslav Zeigerman
76e748146b rebase 2025-07-18 07:30:08 +02:00
Iaroslav Zeigerman
f6f1d076da verify that records remain unchanged after sorting 2025-07-18 07:28:37 +02:00
Iaroslav Zeigerman
d9751212d7 make a fuzz sorter test 2025-07-18 07:28:37 +02:00
Iaroslav Zeigerman
20bdbd5ca5 address suggestions 2025-07-18 07:28:37 +02:00
Iaroslav Zeigerman
edf2be1432 fix conflicts 2025-07-18 07:28:37 +02:00
Iaroslav Zeigerman
6a609398fe cosmetic fix 2025-07-18 07:28:37 +02:00
Iaroslav Zeigerman
a88b828268 Fix clippy 2025-07-18 07:28:36 +02:00
Iaroslav Zeigerman
fd042ac4c8 Use IOResult insteaed of CursorResult 2025-07-18 07:28:36 +02:00
Iaroslav Zeigerman
78f3bf3475 Core: Introduce external sorting 2025-07-18 07:28:36 +02:00
Diego Reis
9ade79b3ad Do not rollback in TxError
Fixes #2153. Not so sure if SQLite doesn't rollback in more cases, we
should definitively check this out.
2025-07-18 01:11:51 -03:00
PThorpe92
a0a948101d Last cleanups of old completion api 2025-07-17 23:47:43 -04:00
PThorpe92
dced94aec6 Replace verbose completions with new helpers 2025-07-17 23:47:21 -04:00
PThorpe92
44d7570272 Add helper/convenience methods for creating io completions 2025-07-17 23:46:55 -04:00
Jussi Saurio
2f2ecb3576 microsoft paperclip 2025-07-17 23:48:31 +03:00
Jussi Saurio
483dc27539 Merge 'make most instrumentation levels to be Debug or Trace instead' from Pedro Muniz
Span creation in debug mode is very slow and impacts our ability to run
the Simulator faster.

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

Closes #2146
2025-07-17 23:45:07 +03:00
Jussi Saurio
746995f436 Merge 'Property FaultyQuery should fail if we encounter an error that is not expected' from Pedro Muniz
If we use `Assumption` here, the simulator just goes to the next
property instead of halting here.

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

Closes #2147
2025-07-17 23:44:44 +03:00
Jussi Saurio
68427c9b31 Merge 'make_from_btree should wait for IO to complete' from Pedro Muniz
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #2144
2025-07-17 23:44:29 +03:00
Jussi Saurio
1b52b5c764 Merge 'chore: update rust to version 1.88.0' from Nils Koch
This PR updates to version Rust 1.88.0 ([Release
notes](https://releases.rs/docs/1.88.0/)) and fixes all the clippy
errors that come with the new Rust version.
This is possible in the latest Rust version:
```rust
if let Some(foo) = bar && foo.is_cool() {
  ...
}
```
There are three complications in the migration (so far):
- A BUNCH of Clippy warnings (mostly fixed in
https://github.com/tursodatabase/limbo/pull/1827)
- Windows cross compilation failed; linking `advapi32` on windows fixes
it
  - Since Rust 1.87.0, advapi32 is not linked by default anymore
([Release notes](https://github.com/rust-
lang/rust/blob/master/RELEASES.md#compatibility-notes-1),
[PR](https://github.com/rust-lang/rust/pull/138233))
- Rust is more strict with FFIs and aligning pointers now. CI checks
failed with error below
  - Fixed in https://github.com/tursodatabase/turso/pull/2064
```
thread 'main' panicked at
core/ext/vtab_xconnect.rs:64:25:
misaligned pointer dereference: address must be
a multiple of 0x8 but is 0x7ffd9d901554
```

Closes #1807
2025-07-17 23:35:33 +03:00
pedrocarlo
4aa2c1a579 Property should fail if we encounter an error that is not expected 2025-07-17 17:01:54 -03:00
pedrocarlo
c15f1e02d3 make most instrumentation levels to be Debug or Trace instead. Span creation in debug mode is very slow and impacts our ability to run the Simulator fast enough 2025-07-17 16:48:24 -03:00
Pekka Enberg
8e98c33fce Ruff you are an idiot 2025-07-17 21:51:34 +03:00
Pekka Enberg
ddc0144dcf core/mvcc: Adjust cursor tests 2025-07-17 21:43:07 +03:00
Pekka Enberg
d11a8063f0 testing: Format mvcc.py to make ruff happy... 2025-07-17 21:39:08 +03:00
pedrocarlo
9690eb41c2 make_from_btree should wait for IO to complete if we do not want to use a state machine 2025-07-17 15:34:42 -03:00
Jussi Saurio
9726b95beb Merge 'translate/create index: fix wrong collations' from Jussi Saurio
We were passing the table columns' collations (all of them) in order,
instead of the index column collations. Two issues:
1. This is wrong
2. There's now an assertion in the Sorter that actually panics if the
length of sort order and collations is not the same

Closes #2140
2025-07-17 21:25:11 +03:00
Jussi Saurio
242301704f Merge 'bind/java: Fix Linux x86 build release' from Diego Reis
> "But it ain't about how hard ya hit. It's about how hard you can get
hit and keep moving forward."
> -- Rocky
Fix ~obviously~ wrong (my bad) Linux build.

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

Closes #2143
2025-07-17 21:24:44 +03:00
Diego Reis
68ad2cf37f bind/java: Fix Linux x86 build release 2025-07-17 15:18:58 -03:00
Jussi Saurio
072cb725a8 Merge 'forgot to set the state to NewTrunk if we have more leaf pages than free entries' from Pedro Muniz
Closes #2142
2025-07-17 21:16:05 +03:00
pedrocarlo
1f67d69e8e forgot to set the state to NewTrunk if we have more leaf pages than free entries 2025-07-17 15:09:52 -03:00
Jussi Saurio
a45ac11462 translate/create index: fix wrong collations 2025-07-17 21:07:48 +03:00
Jussi Saurio
e56325bf05 Merge 'Implement IO latency correctly in simulator' from Pedro Muniz
Closes #1998. Now I am queuing IO to be run at some later point in time.
Also Latency for some reason is slowing the simulator a looot for some
runs.
This PR also adds a StateMachine variant in Balance as now `free_pages`
is correctly an asynchronous function. With this change, we now need a
state machine in the `Pager` so that `free_pages` can be reentrant.
Lastly, I removed a timeout in `checkpoint_shutdown` as it was
triggering constantly due to the slightly increased latency.

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

Closes #1943
2025-07-17 21:05:17 +03:00
Jussi Saurio
bac811caad Merge 'fix/btree: fix insert_into_cell() logic' from Jussi Saurio
## What was wrong
During running simulations for #1988 I ran into a post-balance
validation error where the correct divider cell could not be found from
the parent.
This was caused by divider cell insertion happening this way:
- First divider cell caused overflow
- Second technically had space to fit, so we didn't add it to overflow
cells
- During balance validation, we were not able to find the divider in the
expected slot.
## First fix attempt
I looked at SQLite source, and it seems SQLite always adds the cell to
overflow cells if there are existing overflow cells, and doesn't allow
normal insertion even if the cell payload would fit:
```c
if( pPage->nOverflow || sz+2>pPage->nFree ){
  ...add to overflow cells...
}
```
So, I changed our implementation to do the same, which fixed the balance
validation issue.
## The sequel
However, then I ran into another issue:
A cell inserted during balancing in the `edit_page()` stage was added to
overflow cells, which should not happen. The reason for this was the
changed logic in `insert_into_page()`, outlined above. Since the page
being balanced contained not-yet-cleared overflow cells, any insert to
it ended up being shoved into the overflow cells vector too.
It looks like - unlike us - SQLite doesn't use the equivalent of
`insert_into_cell()` in its implementation of `page_insert_array()`
which explains this.
## Second fix
For simplicity, I made a second version of `insert_into_cell()` called
`insert_into_cell_during_balance()` which allows regular cell insertion
despite existing overflow cells, since the existing overflow cells are
what caused the balance to happen in the first place and will be cleared
as soon as `edit_page()` is done.

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

Closes #2138
2025-07-17 19:06:40 +03:00