关于MySql中explain结果filtered的理解
kevin.Zhu 发布于:2022-4-1 13:39 分类:文摘 有 12 人浏览,获得评论 0 条
https://blog.csdn.net/yuxxz/article/details/122202911
MySql explain语句的返回结果中,filtered字段要怎么理解?
MySql5.7官方文档中描述如下:
The
filtered
column indicates an estimated percentage of table rows filtered by the table condition. The maximum value is 100, which means no filtering of rows occurred. Values decreasing from 100 indicate increasing amounts of filtering.rows
shows the estimated number of rows examined androws
×filtered
shows the number of rows joined with the following table. For example, ifrows
is 1000 andfiltered
is 50.00 (50%), the number of rows to be joined with the following table is 1000 × 50% = 500.
这段文字不是很好理解,举例来说,有如下三个查询语句的explain结果,针对b和c表的显示filtered是100,而针对a表的显示是18。
-
+-------------+-------+--------+---------+---------+------+----------+
-
| select_type | table | type | key | key_len | rows | filtered |
-
+-------------+-------+--------+---------+---------+------+----------+
-
| PRIMARY | a | range | search | 4 | 174 | 18.00 |
-
| PRIMARY | b | eq_ref | PRIMARY | 4 | 1 | 100.00 |
-
| PRIMARY | c | ALL | PRIMARY | 4 | 1 | 100.00 |
我们可以怎么理解filtered的值呢?从filtered的值中得出什么结论呢?到底是100更好还是18更好?
首先,这里的filtered表示通过查询条件获取的最终记录行数占通过type字段指明的搜索方式搜索出来的记录行数的百分比。
以上图的第一条语句为例,MySQL首先使用索引(这里的type是range)扫描表a,预计会得到174条记录,也就是rows列展示的记录数。接下来MySql会使用额外的查询条件对这174行记录做二次过滤,最终得到符合查询语句的32条记录,也就是174条记录的18%。而18%就是filtered的值。
更完美的情况下,应该是使用某个索引,直接搜索出32条记录并且过滤掉另外82%的记录。
因此一个比较低filtered值表示需要有一个更好的索引,假如type=all,表示以全表扫描的方式得到1000条记录,且filtered=0.1%,表示只有1条记录是符合搜索条件的。此时如果加一个索引可以直接搜出来1条数据,那么filtered就可以提升到100%。
由此可见,filtered=100%确实是要比18%要好。
当然,filtered不是万能的,关注执行计划结果中其他列的值并优化查询更重要。比如为了避免出现filesort(使用可以满足order by的索引),即使filtered的值比较低也没问题。再比如上面filtered=0.1%的场景,我们更应该关注的是添加一个索引提高查询性能,而不是看filtered的值。
参考内容:
-
存档
- 2024年2月(1)
- 2024年1月(15)
- 2023年12月(2)
- 2023年11月(7)
- 2023年10月(5)
- 2023年8月(1)
- 2023年6月(3)
- 2023年5月(1)
- 2023年4月(4)
- 2023年3月(14)
- 2023年2月(8)
- 2023年1月(10)
- 2022年12月(21)
- 2022年11月(24)
- 2022年10月(16)
- 2022年9月(16)
- 2022年8月(31)
- 2022年7月(25)
- 2022年6月(10)
- 2022年5月(20)
- 2022年4月(32)
- 2022年3月(16)
- 2022年2月(9)
- 2022年1月(13)
- 2021年12月(7)
- 2021年11月(16)
- 2021年10月(8)
- 2021年9月(12)
- 2021年8月(12)
- 2021年7月(21)
- 2021年6月(13)
- 2021年5月(20)
- 2021年4月(19)
- 2021年3月(9)
- 2021年2月(3)
- 2021年1月(10)
- 2020年12月(16)
- 2020年11月(13)
- 2020年10月(2)
- 2020年9月(17)
- 2020年8月(4)
- 2020年7月(15)
- 2020年6月(5)
- 2020年5月(1)
- 2020年4月(21)
- 2020年3月(44)
- 2020年2月(20)
- 2020年1月(12)
- 2019年12月(9)
- 2019年11月(13)
- 2019年10月(44)
- 2019年9月(18)
- 2019年8月(15)
- 2019年7月(6)
- 2019年6月(17)
- 2019年5月(10)
- 2019年4月(24)
- 2019年3月(6)
- 2019年2月(2)
- 2019年1月(9)
- 2018年12月(16)
- 2018年11月(6)
- 2018年10月(10)
- 2018年9月(7)
- 2018年8月(8)
- 2018年7月(13)
- 2018年6月(20)
- 2018年5月(22)
- 2018年4月(25)
- 2018年3月(34)
- 2018年2月(9)
- 2018年1月(29)
- 2017年12月(13)
- 2017年11月(29)
- 2017年10月(19)
- 2017年9月(24)
- 2017年8月(27)
- 2017年7月(21)
- 2017年6月(35)
- 2017年5月(61)
- 2017年4月(17)
- 2017年3月(5)
- 2016年8月(1)
- 2014年3月(12)
- 2014年2月(25)
- 2014年1月(22)
- 2013年12月(29)
- 2013年11月(19)
- 2013年10月(18)
- 2013年9月(23)
- 2013年8月(24)
- 2013年7月(22)
- 2013年6月(15)
- 2013年5月(11)
- 2013年4月(36)
- 2013年3月(28)
- 2013年2月(35)
- 2013年1月(627)
-
最新文章
- docker 容器镜像日志满了,解决方案
- sshd_config 中文手册:关于ssh 设置的相关总结(ssh最大连接数、ssh连接时长、安全性配置等)
- 如何在 Linux 中使用 SSH ProxyJump 和 SSH ProxyCommand
- ubuntu - apt-get更新非交互式
- /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found
- Golang中,Aes加解密
- Go实现MD5加密的三种方法小结
- go语言 跟 php nodejs通用的加解密代码
- Win10/11 更改 WSL Docker Desktop 存储路径
- go语言使用vscodedebug 输入数据怎么调试
- ubuntu18.04安装Go语言
- 一键生成ssl证书脚本
- 一键生成自签名SSL秘钥证书
- nginx根据不同的域名将反向代理的tcp连接分流到不同的后端服务器上
- WSL2支持systemctl命令
- WSL 双系统端口映射,网络穿透最新教程
- 使用apt-mirror搭建debian本地仓库 apt源 debian源
- vscode设置打开多个标签页
- 使用IPTABLES实现对特定IP,端口流量的精确统计
- 开源免费的知识库文档管理系统(合集+排名)
- Windows 10(21H2)+ LTSC 2021 最新版MSDN官方简体中文原版ISO镜像下载地址
- Typora语法学习-自我总结笔记
- win7原版下载地址
- 解决在 Win7 旗舰版虚拟机中安装 VMware Tools 失败问题
- windows安装QT
- 使用pkg打包zx编写的nodejs程序
- nodejs库-inquirer.js
- 在nodejs代码中使用 import 替代require
- konva教程
- konva中文文档
-
热门文章