Mysql最佳化之BTree索引,mysqlbtree索引

來源:互聯網
上載者:User

Mysql最佳化之BTree索引,mysqlbtree索引

從一道題開始分析:

假設某個表有一個聯合索引(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 哪?同上面類似啦


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


上面問題答案是多少?反正我是不知道!

總結規律可得:



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.