Skip to content

Optimize MAX msg_uid query#1108

Merged
thomasst merged 1 commit intomasterfrom
optimize-imap-max-uid-query
Mar 5, 2026
Merged

Optimize MAX msg_uid query#1108
thomasst merged 1 commit intomasterfrom
optimize-imap-max-uid-query

Conversation

@thomasst
Copy link
Member

@thomasst thomasst commented Mar 5, 2026

EXPLAIN ANALYZE SELECT max(imapuid.msg_uid) AS max_1 
FROM imapuid FORCE INDEX (ix_imapuid_account_id_folder_id_msg_uid_desc) 
WHERE imapuid.account_id = 42791 AND imapuid.folder_id = 464285;

-> Aggregate: max(imapuid.msg_uid)  (cost=921858 rows=1) (actual time=999..999 rows=1 loops=1)↵    -> Covering index lookup on imapuid using ix_imapuid_account_id_folder_id_msg_uid_desc (account_id=42791, folder_id=464285)  (cost=464365 rows=4.57e+6) (actual time=0.664..830 rows=2.03e+6 loops=1)↵


EXPLAIN ANALYZE SELECT msg_uid
FROM imapuid FORCE INDEX (ix_imapuid_account_id_folder_id_msg_uid_desc)
WHERE account_id = 42791 AND folder_id = 464285
ORDER BY msg_uid DESC LIMIT 1;

-> Limit: 1 row(s)  (cost=33 rows=1) (actual time=0.0359..0.036 rows=1 loops=1)↵    -> Covering index lookup on imapuid using ix_imapuid_account_id_folder_id_msg_uid_desc (account_id=42791, folder_id=464285)  (cost=33 rows=321) (actual time=0.0354..0.0354 rows=1 loops=1)↵

@thomasst thomasst force-pushed the optimize-imap-max-uid-query branch from e8bcfa8 to 0b6655a Compare March 5, 2026 18:00
@thomasst thomasst requested a review from a team March 5, 2026 18:01
@thomasst thomasst merged commit 3d599f9 into master Mar 5, 2026
6 of 8 checks passed
@thomasst thomasst deleted the optimize-imap-max-uid-query branch March 5, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants