I have the following table
CREATE TABLE `Config` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`type_id` mediumint(9) DEFAULT NULL,
`content_id` mediumint(9) DEFAULT NULL,
`menu_id` int(11) DEFAULT NULL,
`field` varchar(50) NOT NULL DEFAULT '',
`value` text NOT NULL,
PRIMARY KEY (`id`),
KEY `menu_id` (`menu_id`) USING BTREE,
KEY `type_id` (`type_id`,`content_id`,`menu_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=1;
It's filled with about 800k rows of test data. Whenever I run the following query it takes about 0.4 seconds to complete:
SELECT id, content_id, menu_id, field, `value`
FROM Config
WHERE type_id = ?
AND content_id = ?
An explain tells me, MySQL is doing a full tablescan instead of using an index:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Config ALL 792674 Using where
Can someone please explain what I am doing wrong here? How has the index to be like so it's used here? Sometimes the query has the extra condition AND menu_id = ?
, which should benefit from it, too.