tabEmail Queue has a very slow search rate because missing some index. I see these problems when change a user email (on name), then this queries are executed:
UPDATE `tabEmail Queue` SET `modified_by` = 'email@example.com' WHERE `modified_by` = 'firstname.lastname@example.org' UPDATE `tabEmail Queue` SET `owner` = 'email@example.com' WHERE `owner` = 'firstname.lastname@example.org'
These querys on medium tables (on my test was only 1700 rows) consume more than 1 minutes of query time, so the ERPNext worker crash with a timeout and a MySQL disconnection.
These times can be fixed with 2 index on these columns:
CREATE INDEX optimize_tabEmail_queue_modified_by USING HASH ON `tabEmail Queue`(modified_by); CREATE INDEX optimize_tabEmail_queue_owner USING HASH ON `tabEmail Queue`(owner);
Used HASH because is fastest on = and <=> comparations.