mysql index 複習筆記

來源:互聯網
上載者:User

標籤:

索引類型:

  1、普通索引

create index index_name on test_table(column_name(length));

  2、唯一索引,可以有空值

create unique index index_name on test_table(column_name(length));

     3、主鍵索引,不能有空

     4、複合式索引,遵循“最左首碼”

create index index_name on test_table(column_name1(10),column_name2,column_name3);

建表時,column_name1長度為 16,這裡用 10。這是因為一般情況下名字的長度不會超過10,這樣會加速索引查詢速度,還會減少索引檔案的大小,提高INSERT的更新速度。

如果分別在 column_name1,column_name2,column_name3上建立單列索引,讓該表有3個單列索引,查詢時和上述的複合式索引效率也會大不一樣,遠遠低於我們的複合式索引。雖然此時有了三個索引,但MySQL只能用到其中的那個它認為似乎是最有效率的單列索引。

建立這樣的複合式索引,其實是相當於分別建立了下面三組複合式索引:

(column_name1,column_na

MySQL只對<,<=,=,>,>=,BETWEEN,IN,以及某些時候的LIKE才會使用索引

 

mysql index 複習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.