网站地图    收藏   

主页 > 后端 > mysql数据库 >

Mysql优化之BTree索引 - mysql数据库栏目 - 自学php

来源:自学PHP网    时间:2015-04-16 10:50 作者: 阅读:

[导读] 从一道题开始分析:假设某个表有一个联合索引(c1,c2,c3,c4)一下只能使用该联合索引的c1,c2,c3部分A where c1=x and c2=x and c4x and c3=xB where c1=x and c2=x and c4=x order by...

从一道题开始分析:

假设某个表有一个联合索引(c1,c2,c3,c4)一下——只能使用该联合索引的c1,c2,c3部分
A where c1=x and c2=x and c4>x and c3=x
B where c1=x and c2=x and c4=x order by c3
C where c1=x and c4= x group by c3,c2
D where c1=? and c5=? order by c2,c3
E where c1=? and c2=? and c5=? order by c2,c3

有谁知道下面A-E能否可以使用索引!!为什么?

OK;开始

创建表:

insert into t 
values
('a1','a2','a3','a4','a5'),
('b1','b2','b3','b4','b5');

插入数据:

insert into t 
values
('a1','a2','a3','a4','a5'),
('b1','b2','b3','b4','b5');

添加索引:

alter table t add index c1234(c1,c2,c3,c4);

对第一种情况:说明c1,c2,c3,c4被使用

\

稍作改变:

\

\

使用group by 一般先生成临时文件,在进行排序

\

order by 哪?同上面类似啦

\

稍微改变一下,分析:知道原理都很容易啦!

\

上面问题答案是多少?反正我是不知道!<喎"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+19y94bnmwsm/ybXDo7o8L3A+CjxwPjxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20141117/2014111709271236.png" alt="">

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论