当前位置:  开发笔记 > 编程语言 > 正文

什么是PostgreSQL的EXPLAIN ANALYZE的MySQL等价物

如何解决《什么是PostgreSQL的EXPLAINANALYZE的MySQL等价物》经验,为你挑选了3个好方法。

我想在MySQL中获得类似于PostgreSQL中的EXPLAIN ANALYZE节目的详细查询计划.有同等的吗?



1> plague..:

编辑:虽然不是直接等效或详细解释分析这里有一些你可以看到的工具

mysql提供EXPLAIN和procedure analyze()
http://dev.mysql.com/doc/refman/5.0/en/explain.html
http://dev.mysql.com/doc/refman/5.0/en/procedure-analyse html的


虽然MySQL的解释将返回一个执行计划,但它绝不像PostgreSQL的EXPLAIN**ANALZYE**输出那么详细.我认为MySQL中没有任何内容可以提供如此详细的计划.

2> bash-..:

我没有在MySQL之前使用过PostgreSQL,EXPLAIN EXTENDED它提供了更多信息,EXPLAIN并且可能会提供您正在寻找的信息.



3> Evan Carroll..:
EXPLAIN EXTENDED

MariaDB / MySQL提供了一个称为的东西EXPLAIN EXTENDED。但是,没有替代品EXPLAIN ANALYZEEXPLAIN 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/

例如,这一点从这个例子所,

EXPLAIN ANALYZE SELECT *
FROM history AS h1
WHERE EXISTS (
  SELECT 1
  FROM history AS h2
  WHERE h1.lead_id = h2.lead_id
  GROUP BY lead_id
  HAVING count(is_first OR NULL) > 1
);

会在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 5.7 + / MariaDB 10.1.2+具有“ EXPLAIN FORMAT = JSON”,其中包括相对查询成本。.MySQL 5.6.3+还具有跟踪优化器的选项(https://dev.mysql.com/doc /internals/en/tracing-example.html),在某些方面可以用作PostgreSQL的“ EXPLAIN ANALYZE”
推荐阅读
携手相约幸福
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有