Mysql explain type使用詳解

2021-08-16 20:47:19 字數 2124 閱讀 1991

下面是測試用例,樓主的測試使用的mysql版本是5.6.27-log。

show  create table user_man;

create table `user_man` (

`manid` bigint(20) not null auto_increment,

`manname` varchar(32) default null,

`manage` int(6) default null,

`upd_time` timestamp not null default '2000-01-01 00:00:00' on update current_timestamp,

`blacklist` bigint(20) default '-1' comment '-1,1',

primary key (`manid`),

key `idx_mn` (`manname`) using btree,

key `idx_mid` (`manid`) using btree

) engine=innodb auto_increment=23 default charset=utf8;

show  create table user_woman;

create table `user_woman` (

`womanid` int(11) not null auto_increment,

`womanname` varchar(20) default null,

`womanage` int(6) default null,

primary key (`womanid`)

) engine=innodb auto_increment=7 default charset=utf8;

#執行計畫中type定義說明:

#(1)執行計畫type為all:遍歷全表來查詢

explain  select * from user_man ;

explain select * from user_man where manage in (9,10);#非索引範圍查詢也是走全表

#(2)執行計畫type為index:只遍歷索引樹

explain select manid from user_man;

#(3)執行計畫type為range:索引掃瞄範圍

explain select *from user_man where manid  < 10;

explain select * from user_man where manid in (8,10,9) order by manage;

#(4)執行計畫type為ref:非唯一性掃瞄索引

explain select *from user_man where manname = 'zzk';

#(5) 執行計畫type為eq_ref:唯一性索引掃瞄

explain select * from user_man ,user_woman where user_man.manid = user_woman.womanid;

explain select * from user_man where manid in (select womanid from user_woman);

#(6)執行計畫type為const、system:當mysql對查詢某部分進行優化,並轉換為乙個常量時,使用這些型別訪問。如將主鍵置於where列表中,mysql就能將該查詢轉換為乙個常量

explain select *from user_man where manid = 8;

explain select * from (select * from user_man where manid=8) dd;

#(7)null:mysql在優化過程中分解語句,執行時甚至不用訪問表或索引

explain select * from user_man where manid = (select min(womanid) from user_woman)

#查詢中若使用了覆蓋索引,則該索引僅出現在key列表中(為manid、manname建立了索引,單獨查這兩個字段);

explain select manid ,manname from user_man where manname = 'zzzz' and manage = 43;

Spring MVC JsonView使用詳解

spring 提供了對jackson 非常好的支援,可以檢視此spring jackson demo 來掌握。這裡著重說一下 jsonview的用法 jsonview可以過濾序列化物件的字段屬性,可以使你有選擇的序列化物件。下面看乙個例子 首先我們定義乙個view類,裡面包含我們對 要序列化的字段 ...

Spring MVC JsonView使用詳解

原文出處 spring 提供了對jackson 非常好的支援,這裡著重說一下 jsonview的用法 jsonview可以過濾序列化物件的字段屬性,可以使你有選擇的序列化物件。下面看乙個例子 首先我們定義乙個view類,裡面包含我們對 要序列化的字段 的定義,我們暫時歸為summary 摘要 屬於s...

vue better scroll外掛程式使用詳解

什麼是 better scroll better scroll 是乙個移動端滾動的解決方案,它是基於 iscroll 的重寫,它和 i 的主要區別在 這裡 better scroll 也很強大,不僅可以做普通的滾動列表,還可以做輪播圖 picker 等等。在需要的檔案中新增 import bscor...