当前位置:网站首页>Explain工具实际操作
Explain工具实际操作
2022-07-27 01:40:00 【Hide on jdk】
新建表:
CREATE TABLE `actor` (
`id` int(11) NOT NULL,
`name` varchar(45) DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `film` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `film_actor` (
`id` int(11) NOT NULL,
`film_id` int(11) NOT NULL,
`actor_id` int(11) NOT NULL,
`remark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_film_actor_id` (`film_id`,`actor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我们来看下下面这条sql:
select (select 1 from actor where id = 1) from (select * from film where id = 1) der;
1.肯定是执行from后面的语句
2.在执行内层select语句
3.执行外层select语句
我们用explain来看下结构:
由此可以推出:id越大越先执行,
观察select_type:3.是衍生,也就是一个临时表 2是子查询 1.是主键查询
可以看出sql执行顺序为:从后往前执行

type列
这一列表示关联类型或访问类型,即MySQL决定如何查找表中的行,查找数据行记录的大概范围。依次从最优到最差分别为:system > const > eq_ref > ref > range > index > ALL
system出现的情况:查询衍生表只有一条记录

const出现的情况:
索引走了主键或者唯一键

eq_ref:主键和索引进行连接

ref:走了索引

range:索引的范围

index:扫描全索引就能拿到结果

ALL:全表扫描

key_len列:
key_len计算规则如下:
char(n):如果存汉字长度就是 3n 字节
varchar(n):如果存汉字则长度是 3n + 2 字节,加的2字节用来存储字符串长度,因为
varchar是变长字符串
数值类型
tinyint:1字节
smallint:2字节
int:4字节
bigint:8字节
时间类型
date:3字节
timestamp:4字节
datetime:8字节
如果字段允许为 NULL,需要1字节记录是否为 NULL

为什么是140? 24*3+2+4+20*3+2=140
为什么是4?走了主键,其他索引不生效
10. Extra列
Using where:使用 where 语句来处理结果,并且查询的列未被索引覆盖
Using index:使用覆盖索引

Using index condition:查询的列不完全被索引覆盖,where条件中是一个前导列的范围;
Using filesort:将用外部排序而不是索引排序,数据较小时从内存排序,否则需要在磁盘完成排序
Select tables optimized away
边栏推荐
- Localstorage and sessionstorage
- Annotation summary of differences between @autowired and @resource
- [learn FPGA programming from scratch -54]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Altera)
- Does Oracle have a distributed database?
- 基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
- Worthington过氧化物酶活性的6种测定方法
- 国内服务器与海外服务器用1个数据库,怎样可以访问的快?
- Safe-arc/warner power supply maintenance xenon lamp power supply maintenance analysis
- Pytorch损失函数总结
- Worthington木瓜蛋白酶解离系统解决方案
猜你喜欢

Pytorch损失函数总结

网络安全/渗透测试工具AWVS14.9下载/使用教程/安装教程

Take you to know what Web3.0 is

Message rejected MQ

消息被拒MQ

Deeply understand the underlying data structure and algorithm of MySQL index

“date: write error: No space left on device”解决

Worthington果胶酶的特性及测定方案

Mysql: summary of common sub database and sub table schemes of Internet companies

Explain详解
随机推荐
食物链(DAY 79)
MySQL的数据库有关操作
如何进行 360 评估
关于OpenFeign的源码分析
深入理解Mysql索引底层数据结构与算法
Source code analysis of warning notification for skywalking series learning
Attention should be paid to the first parameter of setTimeout
Worthington果胶酶的特性及测定方案
An error in the fourth edition of the red book?
最低票价(DAY 80)
安全员及环保员岗位职责
Deep learning vocabulary embedded, beam search
客户案例 | 关注老年用户体验,银行APP适老化改造要避虚就实
flask_restful中reqparse解析器继承
Practice of online problem feedback module (XV): realize the function of online updating feedback status
Submodule cache cache failure
Hcip day 14 notes
Customer cases | pay attention to the elderly user experience, and the transformation of bank app to adapt to aging should avoid falsehood and be practical
OC-消息机制
Call jshaman's Web API interface to realize JS code encryption.