I have a query that does this:
SELECT `threaded_comments`.* FROM `threaded_comments` WHERE `threaded_comments`.`parent_id` IN (4, 5)
I’ve also setup an INDEX on the parent_id column.
When I do a EXPLAIN SELECT check on the query I get the following information:
`select_type`,`table`,`type`,`possible_keys`,`key`,`key_len`,`ref`,`rows`,`Extra`
'SIMPLE', 'threaded_comments', 'ALL', 'COMMENT_PARENT', NULL, NULL, NULL, 3, 'Using where'
Looks like no keys are being used for the where clause of the index. However, when I do a simple parent_id = 4 then it works. But when I do parent_id=4 or parent_id=5 then it brings up the same message.
I figured out that it has todo with the innoDB database table type. MySQL seems to not like it when there are IN operations performed on that specific database engine. Could this be a problem with the EXPLAIN tool or it is something that InnoDB is missing?
No, it has nothing to do with InnoDB. Your EXPLAIN plan shows that the query is able to use the index, but MySQL optimizer decided not to use it. The selected decision depends on many factors. But later when your table grows up, the optimizer can make a different decision if it thinks it’s useful. If you want to explicitly use an index on that query then you may try to force index.