Bug #65359 | bad select performance | ||
---|---|---|---|
Submitted: | 18 May 2012 12:41 | Modified: | 30 May 2012 17:01 |
Reporter: | wiliam brana | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 5.1.62 | OS: | Linux |
Assigned to: | CPU Architecture: | Any |
[18 May 2012 12:41]
wiliam brana
[18 May 2012 13:39]
wiliam brana
select takes 85 ms with 5.5.22
[18 May 2012 13:46]
Valeriy Kravchuk
Please, send the output of: explain SELECT * FROM v_posts WHERE forum_id =1 AND thread_id=100 AND order_id < 3001 AND order_id > 2990 ORDER BY order_id LIMIT 10; for cases when tables referred to by the view are both MyISAM (fast) and both InnoDB (slow).
[18 May 2012 14:29]
wiliam brana
InnoDB: mysql> EXPLAIN SELECT * FROM forum.v_posts WHERE forum_id =1 AND thread_id =100 AND order_id <3001 AND order_id >2990 ORDER BY order_id LIMIT 10; +----+-------------+-------+-------------+-------------------------------------+--------------------+---------+---------------------+------+------------------------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------------+-------------------------------------+--------------------+---------+---------------------+------+------------------------------------------------------------------+ | 1 | SIMPLE | posts | index_merge | forum_id,thread_id,user_id,order_id | thread_id,forum_id | 4,4 | NULL | 1499 | Using intersect(thread_id,forum_id); Using where; Using filesort | | 1 | SIMPLE | users | eq_ref | PRIMARY | PRIMARY | 4 | forum.posts.user_id | 1 | | +----+-------------+-------+-------------+-------------------------------------+--------------------+---------+---------------------+------+------------------------------------------------------------------+ 2 rows in set (0.00 sec) MyISAM: mysql> EXPLAIN SELECT * FROM forum.v_posts WHERE forum_id =1 AND thread_id =100 AND order_id <3001 AND order_id >2990 ORDER BY order_id LIMIT 10; +----+-------------+-------+--------+-------------------------------------+-----------+---------+---------------------+------+-----------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+--------+-------------------------------------+-----------+---------+---------------------+------+-----------------------------+ | 1 | SIMPLE | posts | ref | forum_id,thread_id,user_id,order_id | thread_id | 4 | const | 2964 | Using where; Using filesort | | 1 | SIMPLE | users | eq_ref | PRIMARY | PRIMARY | 4 | forum.posts.user_id | 1 | | +----+-------------+-------+--------+-------------------------------------+-----------+---------+---------------------+------+-----------------------------+ 2 rows in set (0.00 sec)
[18 May 2012 21:40]
wiliam brana
I forgot to remove unnecessary "forum_id =1", which seems to cause bad performance.
[22 May 2012 13:24]
Valeriy Kravchuk
Looks like problem may be related to outdated/wrong statistics for InnoDB table. Can you, please, try to run ANALYZE TABLE for InnoDB table several times and check if EXPLAIN results for the problematic query ever change to NOT use index on forum_id.
[22 May 2012 13:51]
wiliam brana
analyze table didn't help
[30 May 2012 17:01]
Sveta Smirnova
Thank you for the feedback. this seems to be duplicate of bug #65274. Please use FORCE/IGNORE INDEX or set optimizer switch, so it does not suppor index merge optimization until it is fixed.