mysql优化之btree索引使用规则 从一道题开始分析: 假设某个表有一个联合索引(c1,c2,c3,c4)一下mdash;mdash;只能使用该联合索
mysql优化之btree索引使用规则
从一道题开始分析:
假设某个表有一个联合索引(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 哪?同上面类似啦
稍微改变一下,分析:知道原理都很容易啦!
上面问题答案是多少?反正我是不知道!
总结规律可得:
--------------------------------------分割线 --------------------------------------
ubuntu 14.04下安装mysql
《mysql权威指南(原书第2版)》清晰中文扫描版 pdf
ubuntu 14.04 lts 安装 lnmp nginx\php5 (php-fpm)\mysql
ubuntu 14.04下搭建mysql主从服务器
ubuntu 12.04 lts 构建高可用分布式 mysql 集群
ubuntu 12.04下源代码安装mysql5.6以及python-mysqldb
mysql-5.5.38通用二进制安装
--------------------------------------分割线 --------------------------------------
本文永久更新链接地址: