Hi Zhang. I'm expending over +40minutes to login into iredadmin pro with mysql backend.
I have applied your final fix (not_delete_old_2.patch) but the same result.
mysql> show full processlist;
| Id | User | Host | db | Command | Time | State | Info
| 76 | vmail | localhost:57242 | vmail | Sleep | 0 | | NULL
| 81 | vmailadmin | localhost:57244 | vmail | Sleep | 1 | | NULL
| 306 | vmail | localhost:43306 | vmail | Sleep | 107 | | NULL
| 308 | vmail | localhost:43309 | vmail | Sleep | 107 | | NULL
| 571 | vmail | localhost:43526 | vmail | Sleep | 1074 | | NULL
| 661 | vmail | localhost:43589 | vmail | Sleep | 1 | | NULL
| 1228 | vmail | localhost:59316 | vmail | Sleep | 1529 | | NULL
| 1861 | vmail | localhost:59800 | vmail | Sleep | 1529 | | NULL
| 1863 | vmail | localhost:59802 | vmail | Sleep | 1530 | | NULL
| 5298 | vmail | localhost:46855 | vmail | Sleep | 1 | | NULL
| 5299 | vmail | localhost:46856 | vmail | Sleep | 1 | | NULL
| 5300 | vmail | localhost:46857 | vmail | Sleep | 1 | | NULL
| 5736 | vmail | localhost:55539 | vmail | Sleep | 16 | | NULL
| 5737 | vmail | localhost:55540 | vmail | Sleep | 16 | | NULL
| 5738 | vmail | localhost:55541 | vmail | Sleep | 16 | | NULL
| 5739 | vmail | localhost:55542 | vmail | Sleep | 16 | | NULL
| 5740 | vmail | localhost:55543 | vmail | Sleep | 18 | | NULL
| 5741 | vmail | localhost:55544 | vmail | Sleep | 18 | | NULL
| 5742 | vmail | localhost:55545 | vmail | Sleep | 18 | | NULL
| 5743 | vmail | localhost:55546 | vmail | Sleep | 18 | | NULL
| 5744 | vmail | localhost:55547 | vmail | Sleep | 0 | | NULL
| 5745 | vmail | localhost:55548 | vmail | Sleep | 23 | | NULL
| 5746 | vmail | localhost:55549 | vmail | Sleep | 23 | | NULL
| 5747 | vmail | localhost:55550 | vmail | Sleep | 23 | | NULL
| 5749 | vmail | localhost:55554 | vmail | Sleep | 3 | | NULL
| 5750 | vmail | localhost:55555 | vmail | Sleep | 3 | | NULL
| 5751 | vmail | localhost:55556 | vmail | Sleep | 0 | | NULL
| 5752 | vmail | localhost:55557 | vmail | Sleep | 3 | | NULL
| 5753 | vmail | localhost:55558 | vmail | Sleep | 3 | | NULL
| 5755 | vmail | localhost:55560 | vmail | Sleep | 0 | | NULL
| 5756 | vmail | localhost:55561 | vmail | Sleep | 0 | | NULL
| 5757 | vmail | localhost:55562 | vmail | Sleep | 0 | | NULL
| 5758 | vmail | localhost:55563 | vmail | Sleep | 26 | | NULL
| 5759 | vmail | localhost:55564 | vmail | Sleep | 56 | | NULL
| 5760 | vmail | localhost:55565 | vmail | Sleep | 56 | | NULL
| 5761 | vmail | localhost:55566 | vmail | Sleep | 56 | | NULL
| 5762 | vmail | localhost:55567 | vmail | Sleep | 56 | | NULL
| 5766 | vmail | localhost:55572 | vmail | Sleep | 0 | | NULL
| 5767 | vmail | localhost:55573 | vmail | Sleep | 0 | | NULL
| 5768 | vmail | localhost:55574 | vmail | Sleep | 0 | | NULL
| 5769 | vmail | localhost:55575 | vmail | Sleep | 0 | | NULL
| 5838 | vmail | localhost:55635 | vmail | Sleep | 26 | | NULL
| 5907 | iredadmin | localhost:55675 | iredadmin | Sleep | 181 | | NULL
| 5908 | vmailadmin | localhost:55676 | vmail | Sleep | 181 | | NULL
| 5909 | vmailadmin | localhost:55677 | vmail | Sleep | 181 | | NULL
| 5910 | vmailadmin | localhost:55678 | vmail | Sleep | 181 | | NULL
| 5911 | vmailadmin | localhost:55679 | vmail | Sleep | 181 | | NULL
| 5912 | amavisd | localhost:55680 | amavisd | Sleep | 181 | | NULL
| 5913 | vmailadmin | localhost:55681 | vmail | Sleep | 181 | | NULL
| 5914 | amavisd | localhost:55682 | amavisd | Query | 181 | Sending data | DELETE FROM msgrcpt WHERE mail_id IN (SELECT mail_id FROM msgs WHERE content IN ('U', 'M', 'H', 'O', 'C') AND time_num < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))
) |
| 5972 | vmail | localhost:55731 | vmail | Sleep | 1 | | NULL
| 5973 | vmail | localhost:55732 | vmail | Sleep | 1 | | NULL
| 5974 | vmail | localhost:55733 | vmail | Sleep | 1 | | NULL
| 5975 | vmail | localhost:55734 | vmail | Sleep | 1 | | NULL
| 6100 | amavisd | localhost:55833 | amavisd | Sleep | 1 | | NULL
| 6137 | amavisd | localhost:55855 | amavisd | Sleep | 1 | | NULL
| 6163 | vmail | localhost:55869 | vmail | Sleep | 56 | | NULL
| 6164 | vmail | localhost:55870 | vmail | Sleep | 56 | | NULL
| 6165 | vmail | localhost:55871 | vmail | Sleep | 56 | | NULL
| 6166 | vmail | localhost:55872 | vmail | Sleep | 56 | | NULL
| 6199 | vmail | localhost:55897 | vmail | Sleep | 16 | | NULL
| 6200 | vmail | localhost:55899 | vmail | Sleep | 16 | | NULL
| 6201 | vmail | localhost:55900 | vmail | Sleep | 16 | | NULL
| 6202 | vmail | localhost:55901 | vmail | Sleep | 16 | | NULL
| 6213 | vmail | localhost:55913 | vmail | Sleep | 34 | | NULL
| 6214 | vmail | localhost:55914 | vmail | Sleep | 34 | | NULL
| 6242 | vmail | localhost:48466 | vmail | Sleep | 16 | | NULL
| 6245 | root | localhost | amavisd | Query | 0 | NULL | show full processlist
68 rows in set (0.00 sec)
mysql> explain select * FROM msgrcpt WHERE mail_id IN (SELECT mail_id FROM msgs WHERE content IN ('U', 'M', 'H', 'O', 'C') AND time_num < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY)));
+----+--------------------+---------+-------+-------------------+-------------------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+---------+-------+-------------------+-------------------+---------+------+--------+-------------+
| 1 | PRIMARY | msgrcpt | ALL | NULL | NULL | NULL | NULL | 359334 | Using where |
| 2 | DEPENDENT SUBQUERY | msgs | range | msgs_idx_time_num | msgs_idx_time_num | 4 | NULL | 105408 | Using where |
+----+--------------------+---------+-------+-------------------+-------------------+---------+------+--------+-------------+
2 rows in set (0.00 sec)
Thanks
Edited:
After create the two indexes suggested above,
mysql> ALTER TABLE msgs ADD INDEX msg_idx_content_time_num (content, time_num);
mysql> ALTER TABLE `msgs` ADD INDEX `mail_id` (`mail_id`);
login takes "only" 15 seconds.
The new query explanation es:
mysql> explain select * FROM msgrcpt WHERE mail_id IN (SELECT mail_id FROM msgs WHERE content IN ('U', 'M', 'H', 'O', 'C') AND time_num < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY)));
+----+--------------------+---------+----------------+----------------------------------------------------+---------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+---------+----------------+----------------------------------------------------+---------+---------+------+--------+-------------+
| 1 | PRIMARY | msgrcpt | ALL | NULL | NULL | NULL | NULL | 358612 | Using where |
| 2 | DEPENDENT SUBQUERY | msgs | index_subquery | msgs_idx_time_num,msg_idx_content_time_num,mail_id | mail_id | 18 | func | 1 | Using where |
+----+--------------------+---------+----------------+----------------------------------------------------+---------+---------+------+--------+-------------+
2 rows in set (0.00 sec)