设为首页 加入收藏

TOP

[MySQL] 测试where group by order by的索引问题
2019-08-23 00:36:38 】 浏览:15
Tags:MySQL 测试 where group order 索引 问题

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;

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇《PHP制作个人博客》之四:分类添.. 下一篇dede二级导航

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目