创建如下表
create table test (
id int auto_increment primary key,
name varchar(20),
age tinyint
)
添加测试数据
insert into test (name, age) values
('zhang', 8),
('wang', 18),
('li', 2),
('zhang', 12),
('zhao', 23),
('zhang', 7),
('li', 12),
('wang', 4)
然后执行
explain select * from test group by name order by id
我要怎么创建索引可以避免using temporary 和 using filesort
你可以再name字段上建立索引