Skip to content

perf(db): index the iMIP invitation scan - #13623

Open
ChristophWurst wants to merge 1 commit into
mainfrom
perf/imip-scan-index
Open

perf(db): index the iMIP invitation scan#13623
ChristophWurst wants to merge 1 commit into
mainfrom
perf/imip-scan-index

Conversation

@ChristophWurst

@ChristophWurst ChristophWurst commented Sep 2, 2026

Copy link
Copy Markdown
Member

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

Bildschirmfoto vom 2026-09-02 14-59-55

^ 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)

  • The content of this PR was partly or fully generated using AI

@ChristophWurst

Copy link
Copy Markdown
Member Author

/backport to stable5.11

@ChristophWurst

Copy link
Copy Markdown
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
kesselb force-pushed the perf/imip-scan-index branch from bd72ab0 to 817b051 Compare September 3, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants