-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3.5+ DB performance analysis #9162
Comments
An idea for avoiding the self-join of the messages table for mailbox listing: EXPLAIN SELECT `m`.`id`, `m`.`sent_at`, m.subject FROM `oc_mail_messages` `m` LEFT JOIN `oc_mail_messages` `m2` ON (`m`.`mailbox_id` = `m2`.`mailbox_id`) AND (`m`.`thread_root_id` = `m2`.`thread_root_id`) AND (`m`.`sent_at` < `m2`.`sent_at`) WHERE (`m`.`mailbox_id` = 7876) AND (`m`.`flag_deleted` = 0) AND (`m2`.`id` IS NULL) ORDER BY `sent_at` DESC LIMIT 20
EXPLAIN SELECT id, min(sent_at), thread_root_id, subject FROM oc_mail_messages where mailbox_id = 7876 group by thread_root_id order by max(sent_at) desc limit 20;
or
EXPLAIN SELECT id, subject FROM oc_mail_messages WHERE mailbox_id = 7876 and thread_root_id IN (SELECT thread_root_id FROM oc_mail_messages where mailbox_id = 7876 group by thread_root_id, thread_root_id order by max(sent_at) desc) limit 20; before/after |
We capture slow queries for CI runs with MySQL. These can be used as indication for queries to optimize, too:
Ref mail/.github/workflows/test.yml Lines 168 to 171 in a2b5a62
Ref mail/.github/workflows/test.yml Lines 184 to 186 in a2b5a62
|
From analyzing tables of a production system: oc_mail_classifiers is the 4th largest table in terms of rows. This can't be right. We only need one classifier per account. The rest is history data that can go. #9001 should take care of that. |
From slow query log and pt-query-digest:
No index used. Possibly due to the large IN clause. To check if an index could help, or restructuring to a join or sub query. |
Would be interesting to test the querys on a large db. On a table with some thousand the self-join is much faster than the min(), max() option. |
Some improvements could be: oc_mail_messages
oc_mail_classifiers
oc_mail_accounts
oc_mail_smime_certificates
oc_mail_tags
oc_mail_aliases
oc_mail_trusted_senders
oc_mail_coll_addresses
|
Manual analysis above confirmed by mariadb-sys:
mail_smime_certs_id_uid_idx is interesting. We only have the index for the purpose of a unique constraint. |
Steps to reproduce
Expected behavior
Fast DB operations
Actual behavior
?
Mail app version
v3.5.0 RC3 / RC4
Mailserver or service
No response
Operating system
No response
PHP engine version
None
Web server
None
Database
None
Additional info
Queries of my personal instance for roughly a day of use with two mail accounts:
it's the number of executions followed by the query
Work packages
The text was updated successfully, but these errors were encountered: