4
我正在通過一個簡單的表執行一個非常簡單的選擇,其中我要過濾的列有一個索引。MySQL索引使用
這裏是架構:
CREATE TABLE IF NOT EXISTS `tmp_inventory_items` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`transmission_id` int(11) unsigned NOT NULL,
`inventory_item_id` int(11) unsigned DEFAULT NULL,
`material_id` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `transmission_id` (`transmission_id`)
KEY `inventory_item_id` (`inventory_item_id`),
KEY `material_id` (`material_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=21 ;
這裏是SQL:
SELECT * FROM `tmp_inventory_items` WHERE `transmission_id` = 330
然而,解釋查詢,我看到一個沒有被使用的索引時,這是爲什麼 (該表在我的本地機器上有大約20行)?
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tmp_inventory_items... ALL transmission_id NULL NULL NULL 13 Using where
即使我暗示與USE INDEX(transmission_id)mysql的無鍵被使用......這在我看來很奇怪(MySQL版本5.5.28)
可能是因爲行計數沒有達到它會覺得需要索引的閾值? – Amit 2013-04-22 09:58:32