explain 解析

EXPLAIN 可以查看 select, delete, insert, replace, update 语句的执行计划(MySQL怎么执行SQL语句的)。

explain 为select 语句中使用到的每一个table 返回一行信息。
它按照MySQL在处理语句时读取它们的顺序列出了输出中的表。

输出的表解析

ColumnJSON NameMeaning
idselect_idThe SELECT identifier
select_typeNoneThe SELECT type
tabletable_nameThe table for the output row
partitionspartitionsThe matching partitions
typeaccess_typeThe join type
possible_keyspossible_keysThe possible indexes to choose
keykeyThe index actually chosen
key_lenkey_lengthThe length of the chosen key
refrefThe columns compared to the index
rowsrowsEstimate of rows to be examined
filteredfilteredPercentage of rows filtered by table condition
ExtraNoneAdditional information

type (join type)值的解释

const 全主键等于查询,

select * from tb1 where primary_key=1;
select * from tb1 where primary_key1 = 1 and primary_key2=2;

通常情况下, key_len= 字段字符数 * 字符集每个字符所占字节数
default null ,会使 key_len+1
变长的字段如varchar,会使key_len+2
int ,key_len=4
bigint, key_len=8

如果可以为null 长度加1
对于 DEFAULT CHARSET=utf8
varchar 3*length + 2 [+ 1] // 多出来的两个字节是为了记录长度的, 最长 65536
对于 DEFAULT CHARSET=utf8mb4
varchar 4 * length + 2 [+ 1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值