perf(db): index the iMIP invitation scan - #13623
Open
ChristophWurst wants to merge 1 commit into
Open
Conversation
kesselb
approved these changes
Sep 2, 2026
ChristophWurst
enabled auto-merge
September 2, 2026 13:51
Member
Author
|
/backport to stable5.11 |
Member
Author
|
/backport to stable5.12 |
IMipService's cron (every ~300s) ran findIMipMessagesAscending, which filtered mail_messages on imip_message plus three flags with a sent_at window and ORDER BY sent_at. No index matched, so every run full-scanned the whole table (~944k rows) and filesorted, usually to return nothing. It was #2 by rows examined on a 903-account instance, 100% full scans. Add mail_msg_imip_idx (imip_message, sent_at): the rare imip_message value makes the leading column selective (1.45% of rows) and sent_at removes the filesort. The mutable flags (imip_processed, imip_error, flag_junk) are left out on purpose to avoid index churn; imip_message flips at most once. Registered via AddMissingIndicesEvent for existing installs and added to the 2022 message-index migration for new ones. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com> Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
kesselb
force-pushed
the
perf/imip-scan-index
branch
from
September 3, 2026 19:16
bd72ab0 to
817b051
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.
IMipService's cron (every ~300s) ran findIMipMessagesAscending, which filtered mail_messages on imip_message plus three flags with a sent_at window and ORDER BY sent_at. No index matched, so every run full-scanned the whole table (~944k rows) and filesorted, usually to return nothing. It was Nr 2 by rows examined on a 903-account instance, 100% full scans.
Add mail_msg_imip_idx (imip_message, sent_at): the rare imip_message value makes the leading column selective (1.45% of rows) and sent_at removes the filesort. The mutable flags (imip_processed, imip_error, flag_junk) are left out on purpose to avoid index churn; imip_message flips at most once. Registered via AddMissingIndicesEvent for existing installs and added to the 2022 message-index migration for new ones.
Assisted-by: Claude:claude-opus-4-8
^ applying the index on that instance shows how full table scans and sorts turn into simple index range scans.
Query time went from 300ms to 3ms.
馃 AI (if applicable)