Inspecting superheroes.db I find duplicate rows in leaf pages

My code goes through and finds all leaf pages than searches them for matches. My code is returning duplicate entries. I noticed for example for Charlie the Owl (New Earth). if you look at page 41 and 83 you can find entries for it. Both seem to be leaf table pages (first bytes is 0x0d).

I believe I have some misunderstanding about how sqllite pages work. Any help would be appreciated.

example query
./your_program.sh superheroes.db “SELECT id, name FROM superheroes WHERE eye_color = ‘Amber Eyes’”

My result:
840|Charlie the Owl (New Earth)
1151|Freak (New Earth)
1874|Meloni Thawne (New Earth)
2077|Lynx II (New Earth)
1151|Freak (New Earth)
2077|Lynx II (New Earth)
840|Charlie the Owl (New Earth)
1874|Meloni Thawne (New Earth)
78|Mari McCabe (New Earth)

Hey @johnlonganecker, there might be an off-by-one error, as the duplicate pages are 42 and 84 (instead of 41 and 83):

Of the two, page 42 is the actual active page:

Page 84, on the other hand, is a free (inactive) page. Normally it shouldn’t have been picked up.

Tip: Rather than scanning all leaf pages, consider limiting your scan to those referenced by interior pages.

Let me know if you’d like help digging into it further.

Thank you! It was my mistake to assume pages were 0 index not 1 index. It is an interesting design choice.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.