Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL与PostgreSQL的EXPLAIN ANALYZE是什么_Mysql_Sql_Database_Postgresql - Fatal编程技术网

MySQL与PostgreSQL的EXPLAIN ANALYZE是什么

MySQL与PostgreSQL的EXPLAIN ANALYZE是什么,mysql,sql,database,postgresql,Mysql,Sql,Database,Postgresql,我想在MySQL中获得一个详细的查询计划,类似于PostgreSQL中的解释分析显示。是否有等效工具?编辑:虽然不是直接等效工具,也不是像解释分析那样详细,但这里有一些工具可以查看 mysql提供解释和过程分析 在MySQL扩展EXPLAIN之前,我没有使用过PostgreSQL,它提供了比EXPLAIN更多的信息,并且可能会提供您想要的信息。为了清楚起见,对已接受答案的评论没有足够的业力添加评论 程序分析的另一个目的是解释, 它分析指定列的数据集并建议最佳数据类型, i、 e.当我们有1000

我想在MySQL中获得一个详细的查询计划,类似于PostgreSQL中的解释分析显示。是否有等效工具?

编辑:虽然不是直接等效工具,也不是像解释分析那样详细,但这里有一些工具可以查看

mysql提供解释和过程分析

在MySQL扩展EXPLAIN之前,我没有使用过PostgreSQL,它提供了比EXPLAIN更多的信息,并且可能会提供您想要的信息。

为了清楚起见,对已接受答案的评论没有足够的业力添加评论

程序分析的另一个目的是解释, 它分析指定列的数据集并建议最佳数据类型, i、 e.当我们有1000行varchar255并且想要检查我们真正需要的长度时,它很有用,f.e.它可能告诉我们varchar23就足够了

MariaDB/MySQL提供了一个名为。然而,没有什么可以替代。EXPLAIN EXTENDED不提供任何时间信息,内部分解也不那么详细

Name: 'EXPLAIN'
Description:
Syntax:
EXPLAIN [explain_type] SELECT select_options

explain_type:
    EXTENDED
  | PARTITIONS

Or:

EXPLAIN tbl_name

The EXPLAIN statement can be used either as a way to obtain information
about how MySQL executes a statement, or as a synonym for DESCRIBE:

o When you precede a SELECT statement with the keyword EXPLAIN, MySQL
  displays information from the optimizer about the query execution
  plan. That is, MySQL explains how it would process the statement,
  including information about how tables are joined and in which order.
  EXPLAIN EXTENDED can be used to obtain additional information.

  For information about using EXPLAIN and EXPLAIN EXTENDED to obtain
  query execution plan information, see
  https://mariadb.com/kb/en/explain/.

o EXPLAIN PARTITIONS is useful only when examining queries involving
  partitioned tables. For details, see
  http://dev.mysql.com/doc/refman/5.5/en/partitioning-info.html.

o EXPLAIN tbl_name is synonymous with DESCRIBE tbl_name or SHOW COLUMNS
  FROM tbl_name. For information about DESCRIBE and SHOW COLUMNS, see
  [HELP DESCRIBE], and [HELP SHOW COLUMNS].

URL: https://mariadb.com/kb/en/explain/
比如说这是,

将在PostgreSQL上生成类似的内容

                                                     QUERY PLAN                                                     
--------------------------------------------------------------------------------------------------------------------
 Seq Scan on history h1  (cost=0.00..82680.50 rows=1100 width=9) (actual time=0.048..0.065 rows=3 loops=1)
   Filter: (SubPlan 1)
   Rows Removed by Filter: 3
   SubPlan 1
     ->  GroupAggregate  (cost=0.00..37.57 rows=1 width=5) (actual time=0.007..0.007 rows=0 loops=6)
           Group Key: h2.lead_id
           Filter: (count((h2.is_first OR NULL::boolean)) > 1)
           Rows Removed by Filter: 0
           ->  Seq Scan on history h2  (cost=0.00..37.50 rows=11 width=5) (actual time=0.003..0.004 rows=2 loops=6)
                 Filter: (h1.lead_id = lead_id)
                 Rows Removed by Filter: 4
 Planning time: 0.149 ms
 Execution time: 0.123 ms
(13 rows)
虽然这是MySQL的等价物

+------+--------------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id   | select_type        | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+------+--------------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|    1 | PRIMARY            | h1    | ALL  | NULL          | NULL | NULL    | NULL |    6 |   100.00 | Using where |
|    2 | DEPENDENT SUBQUERY | h2    | ALL  | NULL          | NULL | NULL    | NULL |    6 |   100.00 | Using where |
+------+--------------------+-------+------+---------------+------+---------+------+------+----------+-------------+
2 rows in set, 2 warnings (0.00 sec)

MySQL 8.0.18本机引入:

MySQL 8.0.18引入了EXPLAIN ANALYZE,它运行查询并生成解释输出,以及关于优化器的期望如何与实际执行相匹配的计时和其他基于迭代器的信息。对于每个迭代器,提供以下信息:

估计执行成本

估计返回的行数

返回第一行的时间到了

返回所有行的时间-实际成本

迭代器返回的行数

循环数

EXPLAIN ANALYZE只能与SELECT语句一起使用

2020年更新解释分析可用

老问题,但只是为了更新,MySQL中也提供了版本8.0.18,您可以使用它,如下所示:

mysql>解释分析从sbtest1中选择计数*,其中k>500000\G *************************** 1. 划船*************************** 解释:->聚合:count0实际时间=178.225..178.225行=1循环=1 ->过滤器:sbtest1.k>500000成本=98896.53行=493204实际时间=0.022..147.502行=625262循环=1 ->使用idx3在sbtest1上进行索引范围扫描成本=98896.53行=493204实际时间=0.021..96.488行=625262循环=1 一行一组0.18秒
尽管MySQL的explain将返回一个执行计划,但它决不像PostgreSQL在explain ANALZYE中的输出那样详细。我不认为MySQL中有任何东西会给出如此详细的计划。我同意horse的观点,没有真正的等价物。我认为您必须打开某种扩展的统计数据并运行查询,然后使用explain和日志的输出来获得类似的结果。小更新MySQL 5.7+/MariaDB 10.1.2+具有explain FORMAT=JSON,其中包括相对查询成本。。MySQL 5.6.3+还提供了跟踪优化器的选项,优化器在某些方面可以用作PostgreSQL的解释分析。根据MySQL文档,解释扩展不再有任何好处:在较旧的MySQL版本中,分区和扩展信息是使用解释分区和解释扩展生成的。这些语法仍然被认为是向后兼容的,但是现在默认情况下启用了分区和扩展输出,因此分区和扩展关键字是多余的,不推荐使用。它们的使用会导致警告,在将来的MySQL版本中,它们将从解释语法中删除。
+------+--------------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id   | select_type        | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+------+--------------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|    1 | PRIMARY            | h1    | ALL  | NULL          | NULL | NULL    | NULL |    6 |   100.00 | Using where |
|    2 | DEPENDENT SUBQUERY | h2    | ALL  | NULL          | NULL | NULL    | NULL |    6 |   100.00 | Using where |
+------+--------------------+-------+------+---------------+------+---------+------+------+----------+-------------+
2 rows in set, 2 warnings (0.00 sec)