mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-27 21:14:21 +01:00
PR #2065 fixed a bug with table btree seeks concerning boundaries of leaf pages. The issue was that if we were e.g. looking for the first key greater than (GT) 100, we always assumed the key would either be found on the left child page of a given divider (e.g. divider 102), which is incorrect. #2065 has more discussion and documentation about this, so read that one for more context. Anyway: We already had similar handling for index btrees, but it was baked into the `BTreeCursor` struct's seek handling itself, whereas #2065 handled this on the VDBE side. This PR unifies this handling for both table and index btrees by always doing the additional cursor advancement in the VDBE. Unfortunately, since indexes may also need to do an additional advance when they are looking for an exact match, this resulted in a bigger refactor than anticipated, since there are quite a few VDBE instructions that may perform a seek, e.g.: `IdxInsert`, `IdxDelete`, `Found`, `NotFound`, `NoConflict`. All of these can potentially end up in a similar situation where the cursor needs one more advance after the initial seek. For this reason, I have extracted a common VDBE helper `fn seek_internal()` which all the interested VDBE instructions will call to delegate their seek logic.