[MySQL] 测试where group by order by的索引问题
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;
上一篇: JS实现鼠标拖拽盒子移动及右键点击盒子消失效果示例
下一篇: ai怎么绘制简约的大脑概念图案?
推荐阅读
-
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL
-
[MySQL] 测试where group by order by的索引问题
-
[MySQL] 测试where group by order by的索引问题
-
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL
-
深入解析mysql中order by与group by的顺序问题_MySQL
-
MySQL 高级(五)排序索引优化 永远小表驱动大表 Order by 关键字的排序优化 Group by 关键字的优化