Merged
Conversation
Without this rows are being missed. Fixes SlugFiller#1
There was a problem hiding this comment.
Pull request overview
This PR fixes SQLite B-tree traversal in SQLiteDatabase.#iterateBTree so that interior B-tree pages (types 2 and 5) also follow the page-header “right-most pointer”, preventing the rightmost subtree (and its rows) from being skipped.
Changes:
- After iterating all interior-page cells, additionally recurse into the interior page’s right-most child pointer at header offset
+8. - Ensures full table/index scans don’t miss rows that live in the rightmost branch of interior nodes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Without this rows are being missed. This fixes #1.
Written by Claude but I tested that it now indeed works for me.
Bug Found: Missing Right-Most Pointer in Interior B-Tree Pages
The bug is in
#iterateBTree. SQLite's B-tree interior pages (types2and5) store N child pointers inside cells, plus one extra "right-most pointer" in the page header at offset+8. The current code iterates all cells but never follows this right-most pointer, so the entire rightmost subtree is silently skipped — causing rows to be missed for any table whose B-tree has interior pages.Why this happens
SQLite interior B-tree pages have this structure:
Each cell in an interior page holds a left child pointer + a key. The right-most child (which contains all rows with keys greater than the last cell's key) is only stored in the header, not in any cell. For a table with
Ninterior-page children, the loop visitsN-1of them and silently drops the last one — which can represent a large fraction of the rows.