mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 05:24:22 +01:00
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.