我正在对一个简单的表执行一个非常简单的选择,其中我过滤的列有一个索引。
这是架构:
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)