我正在调整 mysql 的查询。 该模式具有 user_id 索引(以下..) 但没有使用索引。为什么?
环境: MySQL4.0.27,MyISAM
SQL 如下:
SELECT type,SUM(value_a) A, SUM(value_b) B, SUM(value_c) C
FROM big_record_table
WHERE user_id='<user_id>'
GROUP BY type
解释:
|table |type |possible_keys |key |key_len |ref |rows |Extra|
|big_record_table| ALL| user_id_key|||| 1059756 |Using where; Using temporary; Using filesort|
您能详细描述一下吗?
方案如下:
CREATE TABLE `big_record_table` (
`user_id` int(11) NOT NULL default '0',
`type` enum('type_a','type_b','type_c') NOT NULL default 'type_a',
`value_a` bigint(20) NOT NULL default '0',
`value_b` bigint(20) default NULL,
`value_c` bigint(20) NOT NULL default '0',
KEY `user_id_key` (`user_id`)
) TYPE=MyISAM
最佳答案
我的猜测是,type
和 user_id
没有索引
。
只是一个意志运行。你没有给予太多可玩的东西。
关于sql - 为什么我的mysql不使用索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3974353/