1. select * from test  where a=xx group by b order by c   如何加索引

CREATE TABLE `index_test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '',
`gid` int(11) NOT NULL DEFAULT '0',
`age` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

 

mysql> select * from index_test;
+----+------------+-----+
| id | name | gid |
+----+------------+-----+
| 1 | taoshihan | 2 |
| 2 | taoshihan1 | 2 |
+----+------------+-----+

2. 加个联合索引试试

alter table index_test add index name_gid_age_index(name,gid,age);

 

explain select * from index_test where name='taoshihan' group by gid order by age;

[MySQL] 测试where group by order by的索引问题

 

相关文章:

  • 2022-12-23
  • 2021-03-30
  • 2021-07-24
  • 2021-06-02
  • 2022-12-23
  • 2021-10-25
  • 2022-01-25
猜你喜欢
  • 2022-02-14
  • 2021-12-29
  • 2022-12-23
  • 2021-05-20
  • 2021-09-27
  • 2021-08-11
相关资源
相似解决方案