当前位置:网站首页>关于MySql中explain结果filtered的理解
关于MySql中explain结果filtered的理解
2022-08-01 16:58:00 【m0_61083409】
MySql explain语句的返回结果中,filtered字段要怎么理解?
MySql5.7官方文档中描述如下:
The
filteredcolumn 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.rowsshows the estimated number of rows examined androws×filteredshows the number of rows joined with the following table. For example, ifrowsis 1000 andfilteredis 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的值。
参考内容:
MySQL :: MySQL 5.7 Reference Manual :: 8.8.2 EXPLAIN Output Format
innodb - What is the meaning of filtered in MySQL explain? - Database Administrators Stack Exchange
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 22年镜头“卷”史,智能手机之战卷进死胡同
- 素域和扩域
- 深圳市商务局2022年度中央资金(跨境电子商务企业市场开拓扶持事项)申报指南
- [Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails
- 吴恩达机器学习课后习题——kmeans
- PHP security flaws: session hijacking, cross-site scripting, SQL injection and how to fix them
- 下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》
- 【黑马早报】胡军代言悟空理财涉嫌欺诈,疑似涉及390亿元;涪陵榨菜回应榨菜吃出脚指甲; 鸿星尔克再捐1个亿;腾讯控股股价跌回5年前...
- MySQL加锁案例分析
- Winform的UI帮助类——部分组件会使用到DevExpress组件
猜你喜欢

14年测试人最近的面试经历,值得借鉴√

我的新书销量1万册了!

zabbix部署和简单使用

京东软件测试面试题,仅30题就已经拯救了50%的人
![[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails

Use Canvas to implement mobile phone signature

Complete knapsack problem to find the number of combinations and permutations

MySQL最大建议行数2000w, 靠谱吗?

下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》

Vulnhub target drone: HARRYPOTTER_ NAGINI
随机推荐
[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails
2022.08月--pushmall推贴共享电商更新与开发计划
个人日记
下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》
C# CSV format file helper class
短剧正在抢长剧的生意
JumpServer堡垒机部署
关于2022年深圳市福田区支持高端服务业发展项目的申报通知
阿里官方 Redis 开发规范
03 gp cluster construction
MySQL加锁案例分析
金仓数据库 KDTS 迁移工具使用指南(2. 简介)
好家伙,公司服务器直接热崩掉了!
TiFlash 存储层概览
05 doris 集群搭建
ROS2系列知识(5):【参数】如何管理?
C# LibUsbDotNet 在USB-CDC设备的上位机应用
程序员架构修炼之道:如何设计“易理解”的系统架构?
22年镜头“卷”史,智能手机之战卷进死胡同
Flask框架实战