gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-29 00:16:05 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com