mysql多列索引

來源:互聯網
上載者:User

標籤:xxx   需要   資料   and   記錄   通過   select   尋找   二分法   

1,資料庫每次查詢只能使用一個索引

2,假設資料 表T (a,b,c) rowid 為物理位置
rowid a b c
(1) 1 1 1
(2) 2 1 13
(3) 2 2 14
(4) 1 3 3
(5) 2 3 12
(6) 1 2 5
(7) 2 3 9
(8) 1 2 2
(9) 1 3 6
(10) 2 2 11
(11) 2 2 8
(12) 1 1 7
(13) 2 3 15
(14) 1 1 4
(15) 2 1 10

當你建立一個索引 create index xxx on t(a,b), 則索引檔案邏輯上等同於如下
a b rowid
1 1 1
1 1 12
1 1 14
1 2 6
1 2 8
1 3 4
1 3 9
2 1 2
2 1 15
2 2 3
2 2 10
2 2 11
2 3 5
2 3 7
2 3 13

當select * from T where a=1 and b=3 的時候, 資料庫系統可以直接從索引檔案中直接二分法找到A=1的記錄,然後再B=3的記錄。
但如果你 where b=3 則需要遍曆這個索引表的全部!

 

3,通過上面執行個體可知,索引類似goup,聯合索引中下一個元素是在符合上一個元素條件記錄中尋找相關記錄。

mysql多列索引

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.