Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.1.16
-
None
-
MariaDB-10.1.16 - Compiled from source
Invision Power Board Software
CentOS 7
PHP 7
Description
I have some issues where the query planner is selecting the wrong index when running queries. The odd part is that it does not match what the EXPLAIN says for the same query in most cases.
Example:
SELECT pid FROM `forums_posts` WHERE topic_id=106927 AND (queued=0 OR queued=2) ORDER BY post_date asc LIMIT 0,25; |
Attached a screenshot of the indexes on the table.
It should be using the first_post index, but it is not. When I run EXPLAIN on this query, it gives this:
1 SIMPLE forums_posts index topic_id,queued,first_post post_date 5 NULL 320 Using where
|
Here is the slow query log:
# Query_time: 7.583572 Lock_time: 0.000034 Rows_sent: 25 Rows_examined: 3044158
|
# Rows_affected: 0
|
SET timestamp=1471611190;
|
/*IPS\Content\_Item::_comments:1635*/ SELECT pid FROM `forums_posts` WHERE topic_id=106927 AND (queued=0 OR queued=2) ORDER BY post_date asc LIMIT 0,25;
|
The engine is clearly using the wrong index - there is no other reason it would be examining over 3 million rows and taking so long to finish. It's worth noting that when I run this query manually and include FORCE INDEX(first_post) it works correctly in 0.001 seconds or similar. Let me know if you need any other info or details!
Thanks.