Quel est L'équivalent MySQL de PostgreSQL EXPLAIN ANALYZE

Je voudrais obtenir un plan de requête détaillé dans MySQL similaire à EXPLAIN ANALYZE shows dans PostgreSQL. Est-t-il un équivalent?

23
demandé sur foolish 2011-07-25 10:55:55

4 réponses

EDIT: bien que ce ne soit pas un équivalent direct ou aussi détaillé que Explain Analyze voici quelques outils que vous pouvez regarder

Mysql propose d'EXPLIQUER et de procédure analyse()
http://dev.mysql.com/doc/refman/5.0/en/explain.html
http://dev.mysql.com/doc/refman/5.0/en/procedure-analyse.html

15
répondu plague 2011-07-25 20:34:50

Je n'ai pas utilisé PostgreSQL avant que MySQL ait EXPLAIN EXTENDED qui donne plus d'informations que EXPLAIN et peut vous donner les informations que vous recherchez.

8
répondu bash- 2011-07-25 08:11:24

Juste pour plus de clarté, commenter la réponse acceptée (ne pas avoir assez de karma pour ajouter un commentaire)

La procédure analyse () est dans un but différent qui explique, il analyse l'ensemble de données de la colonne spécifiée et suggère le meilleur type de données, c'est utile quand on a 1000 lignes de type varchar(255) et que vous souhaitez vérifier combien de longueur-nous vraiment besoin, f.e. on pourrait dire que varchar(23) suffirait

3
répondu timtofan 2013-11-19 18:44:59

EXPLAIN EXTENDED

MariaDB / MySQL fournit quelque chose appelé EXPLAIN EXTENDED. Cependant il n'y a pas de substitut pour EXPLAIN ANALYZE. EXPLAIN EXTENDED ne fournit aucune information de synchronisation, et la panne interne est beaucoup moins verbeuse.

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/

Par exemple prises à partir de cet exemple,

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
);

Produira quelque chose comme ça sur 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)

Bien que ce soit L'équivalent 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)
1
répondu Evan Carroll 2017-06-26 23:45:21