首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[MySQL] 测试where group by order by的索引问题

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

作者头像
唯一Chat
发布2019-09-10 11:09:41
1.3K0
发布2019-09-10 11:09:41
举报
文章被收录于专栏:陶士涵的菜地陶士涵的菜地

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;

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-03-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档