Files
turso/core/storage
Jussi Saurio 49b9a69c40 fix/btree: fix insert_into_cell() logic
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

I looked at SQLite source, and it seems SQLite always adds the cell to overflow
cells if there are existing overflow cells:

```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.

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.

It looks like SQLite doesn't use `insert_into_cell()´ in its implementation of `page_insert_array()`
which explains this.

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.
2025-07-17 18:26:14 +03:00
..
2025-07-16 13:54:39 -03:00
2025-07-15 16:34:07 +08:00