perf(db): index mailbox list sort and recipient lookup - #13502
Open
ChristophWurst wants to merge 1 commit into
Open
perf(db): index mailbox list sort and recipient lookup#13502ChristophWurst wants to merge 1 commit into
ChristophWurst wants to merge 1 commit into
Conversation
The mailbox list query (mailbox_id + flag_deleted, ORDER BY sent_at) had no covering index and fell back to a filesort; the standalone sent_at index was dropped in 2022 and never restored. mail_recipients.local_message_id had a foreign key but no backing index, so lookups and deletes scanned the whole table on Postgres and SQLite. Register both via AddMissingIndicesEvent so existing installations add them out-of-band through occ db:add-missing-indices, and add them to the creating migrations so new installations get them up front. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
Member
Author
|
@CodeRabbit ai review and evaluate the before/after of the PR description against the code base |
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.
The mailbox list query (mailbox_id + flag_deleted, ORDER BY sent_at) had no covering index and fell back to a filesort; the standalone sent_at index was dropped in 2022 and never restored. mail_recipients.local_message_id had a foreign key but no backing index, so lookups and deletes scanned the whole table on Postgres and SQLite.
Register both via AddMissingIndicesEvent so existing installations add them out-of-band through occ db:add-missing-indices, and add them to the creating migrations so new installations get them up front.
Assisted-by: Claude:claude-opus-4-8
How to test
^ replace IDs with something existent of your local db.
Before:
1|SIMPLE|m|ref|mail_messages_mb_id_uid_uidx,mail_msg_thrd_root_snt_idx,mail_msg_by_remote_id_idx|mail_messages_mb_id_uid_uidx|4|const|1|Using where; Using filesort1|SIMPLE|m|ref|mail_messages_mb_id_uid_uidx,mail_msg_thrd_root_snt_idx,mail_msg_by_remote_id_idx|mail_messages_mb_id_uid_uidx|4|const|525|Using where; Using filesortAfter
1|SIMPLE|m|ref|mail_messages_mb_id_uid_uidx,mail_msg_thrd_root_snt_idx,mail_msg_by_remote_id_idx,mail_msg_mb_del_snt_idx|mail_msg_mb_del_snt_idx|6|const,const|1|Using where; Using index1|SIMPLE|m|range|mail_messages_mb_id_uid_uidx,mail_msg_thrd_root_snt_idx,mail_msg_by_remote_id_idx,mail_msg_mb_del_snt_idx|mail_msg_mb_del_snt_idx|10||51|Using where; Using index-> no more filesort
馃 AI (if applicable)