mysql中能夠使用索引的典型情境

來源:互聯網
上載者:User

標籤:nload   聯合   from   and   匹配   explain   http   sql   span   

mysql 示範資料庫:http://downloads.mysql.com/docs/sakila-db.zip

匹配全值

 

explain select * from rental where rental_date=‘2005-05-25 17:22:10‘ and inventory_id=373 and customer_id=343

 

 

匹配值的範圍查詢

 

 

explain select * from rental where customer_id >= 373 and customer_id<400

 

 

匹配最左首碼

 

僅僅使用索引中的最左列進行查詢,比如:在col1+col2+col3欄位上的聯合索引中,能夠使用的索引情況可以有:col1 (col2+col3) ,col1+col2+col3。不能被使用的索引:col2 (col2+col3) 等情況。以payment表為例

 

alter table payment add index idx_payment_date (payment_date,amount,last_update);

 

 

 

explain select * from payment where payment_date=‘2006-02-14 15:16:03‘ and last_update=‘2006-02-15 22:12:32‘\G;

 

 

 explain select * from payment where amount=3.98 and last_update=‘2006-02-15 22:12:32‘\G;

 

 

 僅僅對索引進行查詢

 

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.