Repository navigation
apple: lookup indexes and a text-only search trigger (schema migration) - #175
Merged
Merged
Conversation
morajabi
force-pushed
the
claude/lookup-indexes-migration
branch
from
November 27, 2026 20:31
a5a200d to
de91d18
Compare
morajabi
marked this pull request as ready for review
November 27, 2026 20:31
morajabi
force-pushed
the
claude/lookup-indexes-migration
branch
from
November 28, 2026 14:53
de91d18 to
3a99c2c
Compare
…duplicated indexes, re-index message search only on text changes (schema migration)
morajabi
force-pushed
the
claude/lookup-indexes-migration
branch
from
November 28, 2026 15:41
3a99c2c to
2487c6c
Compare
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.
What the migration does
dialog(chatId): the chat list joins dialogs by chat, so SQLite built an automatic index on every chat list read.chat(parentChatId, parentMessageId) WHERE parentChatId IS NOT NULL: reply-thread lookups by parent message, used by message bundles and the chat list. They scannedchat.chat(peerUserId) WHERE peerUserId IS NOT NULL: DM chats by peer.member(spaceId): space member lists.attachment_messageId_idxandfile_profileForUserId_idx. Each has a partial… IS NOT NULLtwin on the same column. The twin serves every equality,INand join lookup, including the foreign-key scans on message and user deletes. Every insert maintained both B-trees.textorglobalId, with GRDB's trigger body unchanged. Targeted updates (status, revision, resource flags, history pages) no longer delete and re-insert the message's text in the search index. Full-record saves set every column and still re-index, as before.Measured
M5 Mac, 120k-message SQLCipher file:
SCAN chatSEARCH chat_parent_idxTests
New
LookupIndexesMigrationTests:AFTER UPDATE OF "text", "globalId". The migration runs after the read-cursor migration.integrity-checkwith rank 1 (index against the table) passes.chat_parent_idxand dialogs-by-chat usedialog_chatId_idx; the chat list SQL has no automatic index. These checks fail without the migration.=,IN,LEFT JOIN) use the partial twins.DatabaseMigrationOrderTestspass.Review
An independent review checked:
globalIdis the rowid and the trigger body matches GRDB 7.12;On downgrade, an older release build ignores the unknown migration and keeps working. It doesn't recreate the dropped indexes or the old trigger. An older Debug build erases the database, as with any new migration.
Its test fixes are in: pinned upgrade base, rank-1 integrity check, and plan checks for the dropped indexes. Its notes on what still re-indexes and on a future FTS rebuild are in the migration's comment.
No protocol change.
🤖 Generated with Claude Code