MySQL EXPLAIN EXTENDED 过滤列(显然不是百分比)

标签 mysql explain

我一直在寻找这个,他们都说某种百分比,解释一下:

EXPLAIN EXTENDED SELECT * FROM PageAccess ORDER BY AccessId DESC LIMIT 20;
SELECT COUNT(*) FROM PageAccess;

给予:

id, select_type, table, type, possible_keys, key, key_len, ref, rows, filtered, Extra
1, 'SIMPLE', 'PageAccess', 'index', '', 'PRIMARY', '4', '', 20, 9295.00, ''

(是,过滤 = 9295.00)

和:

1830

对于计数(*)

是的,我想要最后 20 行,AccessId 是自动递增的主键。

9295是什么意思!?

最佳答案

来源 http://dev.mysql.com/doc/refman/5.5/en/explain-output.html#explain_filtered

The filtered column indicates an estimated percentage of table rows that will be filtered by the table condition. That is, rows shows the estimated number of rows examined and rows × filtered / 100 shows the number of rows that will be joined with previous tables. This column is displayed if you use EXPLAIN EXTENDED.

在过滤后的 100% 表示此表中的所有行都被过滤。 因此,获得更高的值(value)并不令人担忧,因为这是一个好兆头,意味着它 不必从表中读取尽可能多的数据。

这是它的计算方式。假设我有一个名为 users 的表,让我们对其进行一些分析。

mysql> select count(*) from users ;
+----------+
| count(*) |
+----------+
|    79309 |
+----------+

您可以看到表格中有 79309 行。现在让我们运行解释

mysql> explain extended select * from users order by idusers desc limit 20 ;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-----------+-------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | filtered  | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-----------+-------+
|  1 | SIMPLE      | users | index | NULL          | PRIMARY | 4       | NULL |   20 | 396545.00 |       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-----------+-------+

现在想知道为什么 filtered = 396545.00

计算很简单。

表格的总行数 = 79309 说它的 tx。

解释显示 rows = 20 表示它的 tx1。

过滤后的计算方式为

(tx / tx1)*100 = 396545.00

因此,如果此值很高,则表示查询很好,并且没有从表中读取所有内容。

所以不要混淆这不是查询将查看的行数,它是相对于获取的行数可用的行数的百分比计算。

如果变为 100,则表示查询正在查找表中的所有可用行。

关于MySQL EXPLAIN EXTENDED 过滤列(显然不是百分比),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22969672/

相关文章:

mysql - 如何使用 MYSQL 查询检索统计页面的数据

php - 如何在 PHP 中使用 mysql 循环和 xlsxwriter php 导出到 Excel 工作表

MySQL 格式良好的查询不会使用 equal 和 Between 检索任何结果

MySQL:在这种简单的情况下,何时应用 where 条件检查和文件排序操作?

sql - PostgreSQL:如何阅读并行解释分析(行与单线程不匹配)

mysql - 按取决于当前时间的条件进行排序的正确方法是什么?

c# - 使用 C# 添加 entityFramework 部分

MySQL 将列导入到与键匹配的表中

mysql - 使用 EXPLAIN 优化 MySQL 查询

mysql - 为什么 "explain"返回的行不等于 count()?