mysql的執行計划的type詳解


type 這一列表示關聯類型或訪問類型,即MySQL決定如何查找表中的行。

執行效率排序

#1.system

#2.const * mysql能對查詢的某部分進行優化並將其轉化成一個常量。用於 primary key 或 unique key 的所有列與常數比較時,所以表最多有一個匹配行,讀取1次,速度比較快。
explain select * from (select * from film where id = 1) tmp;

#3.eq_ref * primary key 或 unique key 索引的所有部分被連接使用 ,最多只會返回一條符合條件的記錄。這可能是在 const 之外最好的聯接類型了,簡單的 select 查詢不會出現這種 type。
explain select * from film_actor left join film on film_actor.film_id = film.id;

#4.ref * 相比eq_ref,不使用唯一索引,而是使用普通索引或者唯一性索引的部分前綴,索引要和某個值相比較,可能會找到多個符合條件的行。
explain select * from film where name = "film1";

#5.fulltext

#6.ref_or_null * 類似ref,但是可以搜索值為NULL的行。
explain select * from film where name = "film1" or name is null;

#7.index_merge

#8.unique_subquery

#9.index_subquery

#10.range * 范圍掃描通常出現在 in(), between ,> ,<, >= 等操作中。使用一個索引來檢索給定范圍的行。
explain select * from actor where id > 1;

#11.index * 和ALL一樣,不同就是mysql只需掃描索引樹,這通常比ALL快一些。
explain select count(*) from film;

#12.ALL * 即全表掃描,意味着mysql需要從頭到尾去查找所需要的行。通常情況下這需要增加索引來進行優化了
explain select * from actor;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM