当前位置:网站首页>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
边栏推荐
猜你喜欢

Attention should be paid to the first parameter of setTimeout

深度学习——词汇embedded、Beam Search
![[learn FPGA programming from scratch -54]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Altera)](/img/4f/f75cfeb4422120ef9ac70cdeb0a840.png)
[learn FPGA programming from scratch -54]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Altera)
![[从零开始学习FPGA编程-54]:高阶篇 - 基于IP核的FPGA开发-PLL锁相环IP核的原理与配置(Altera)](/img/4f/f75cfeb4422120ef9ac70cdeb0a840.png)
[从零开始学习FPGA编程-54]:高阶篇 - 基于IP核的FPGA开发-PLL锁相环IP核的原理与配置(Altera)

Explain

Idea 中添加支持@Data 插件

Functions that should be selected for URL encoding and decoding

安全员及环保员岗位职责

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

队列达到最大长度代码实战
随机推荐
sqlserver select * 能不能排除某个字段
水仙花数(DAY 78)
$128million! IQM, a Finnish quantum computing company, was supported by the world fund
30分钟彻底弄懂 synchronized 锁升级过程
OC-消息机制
spark学习笔记(五)——sparkcore核心编程-RDD转换算子
Boom 3D new 2022 audio enhancement app
Code practice when the queue reaches the maximum length
Worthington果胶酶的特性及测定方案
Learn the recycling mechanism of recyclerview again
FactoryBean的getObject调用时机
Indexing best practices
图解 SQL,这也太形象了吧!
数据库概论 - MySQL的简单介绍
Take you to know what Web3.0 is
Mysql: summary of common sub database and sub table schemes of Internet companies
Leetcode 207. curriculum (July 26, 2022)
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
深度学习——词汇embedded、Beam Search
Jmeter分布式压测