Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This seems to be a bug in MySQL 5.1.52. The same query is processed differently before MySQL daemon restart and after restart. Before restart MySQL is performing a week or so, and starts working really slowly. Seems, that optimization is not performed. After restart, everything is OK again.
- BEFORE MySQL restart (przed restartem):
- mysql> explain SELECT BS.ID,ROOT_ID,CMT.COMP_TYPE FROM TAB_3M AS BS JOIN TAB_60 AS CMT ON BS.COMP_TYPE_ID=CMT.ID JOIN TAB_9K AS TR ON BS.ROOT_ID=TR.ATTR_ID WHERE (IFNULL(TR.LATEST_TERM,(NOW() + INTERVAL 1 DAY))>NOW()) AND TR.STATUS & 13=13 AND ( (CMT.COMP_TYPE IN ("string0") AND (IFNULL(COMP_KEYWORD,'')='')) OR PROTOTYPE_ID IN ("string1","string2")) ORDER BY COMP_NAME, ROOT_ID, LFT;
- +----+-------------+-------+--------+-----------------------------------+---------+---------+--------------------+---------+-----------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+--------+-----------------------------------+---------+---------+--------------------+---------+-----------------------------+
- | 1 | SIMPLE | BS | ALL | PROTOTYPE_ID,ROOT_ID,COMP_TYPE_ID | NULL | NULL | NULL | 3121118 | Using where; Using filesort |
- | 1 | SIMPLE | TR | eq_ref | PRIMARY | PRIMARY | 8 | db.BS.ROOT_ID | 1 | Using where |
- | 1 | SIMPLE | CMT | eq_ref | PRIMARY,COMP_TYPE | PRIMARY | 8 | db.BS.COMP_TYPE_ID | 1 | Using where |
- +----+-------------+-------+--------+-----------------------------------+---------+---------+--------------------+---------+-----------------------------+
- 3 rows in set (0.00 sec)
- AFTER MySQL restart (po restarcie):
- mysql> explain SELECT BS.ID,ROOT_ID,CMT.COMP_TYPE FROM TAB_3M AS BS JOIN TAB_60 AS CMT ON BS.COMP_TYPE_ID=CMT.ID JOIN TAB_9K AS TR ON BS.ROOT_ID=TR.ATTR_ID WHERE (IFNULL(TR.LATEST_TERM,(NOW() + INTERVAL 1 DAY))>NOW()) AND TR.STATUS & 13=13 AND ( (CMT.COMP_TYPE IN ("string0") AND (IFNULL(COMP_KEYWORD,'')='')) OR PROTOTYPE_ID IN ("string1","string2")) ORDER BY COMP_NAME, ROOT_ID, LFT;
- +----+-------------+-------+--------+-----------------------------------+-------------+---------+--------------------+------+-----------------------------------------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+--------+-----------------------------------+-------------+---------+--------------------+------+-----------------------------------------------------------+
- | 1 | SIMPLE | TR | index | PRIMARY | TR_STATUS_2 | 6 | NULL | 7622 | Using where; Using index; Using temporary; Using filesort |
- | 1 | SIMPLE | BS | ref | PROTOTYPE_ID,ROOT_ID,COMP_TYPE_ID | ROOT_ID | 9 | db.TR.ATTR_ID | 146 | Using where |
- | 1 | SIMPLE | CMT | eq_ref | PRIMARY,COMP_TYPE | PRIMARY | 8 | db.BS.COMP_TYPE_ID | 1 | Using where |
- +----+-------------+-------+--------+-----------------------------------+---------------+---------+------------------+------+-----------------------------------------------------------+
- 3 rows in set (0.00 sec)
- Explanation:
- TAB_3M - table with about 3 million rows
- TAB_9K - table with about 9 thousand rows
- TAB_60 - table with about 60 rows
Advertisement
Add Comment
Please, Sign In to add comment