Postgre와 동등한 MySQL은 무엇입니까?SQL의 설명 분석
Postgre의 EXPLAINE ANALIZE 쇼와 유사한 MySQL의 자세한 쿼리 계획을 얻고 싶습니다.SQL. 이와 동등한 것이 있습니까?
편집: 여기서 분석을 설명하는 것만큼 직접적으로 동등하거나 상세하지는 않지만 몇 가지 도구를 살펴볼 수 있습니다.
mysql은 설명 및 절차 분석을 제공합니다().
https://dev.mysql.com/doc/refman/8.0/en/explain.html
http://dev.mysql.com/doc/refman/5.0/en/procedure-analyse.html
Postgre를 사용하지 않았습니다.MySQL 이전의 SQLEXPLAIN EXTENDED더 많은 정보를 주는 것은EXPLAIN그리고 당신이 찾고 있는 정보를 줄 수도 있습니다.
MySQL 8.0.18에는 기본적으로 EXPLAYANGE:
MySQL 8.0.18에는 쿼리를 실행하고 타이밍과 함께 EXPLAINE 출력을 생성하는 EXPLAINE ANALIZE가 소개되어 있으며 옵티마이저의 기대치가 실제 실행과 어떻게 일치하는지에 대한 반복자 기반의 정보가 추가되어 있습니다.각 반복기에 대해 다음과 같은 정보가 제공됩니다.
예상실행비용
반환된 예상 행 수
첫번째 행을 반환할 시간
모든 행을 반환하는 시간(실제 비용)
반복기에서 반환되는 행 수
고리수
EXCEL ANALIZE는 SELECT 문에서만 사용할 수 있습니다.
EXPLAIN EXTENDED
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/
예를 들어 이 예에서 따온 것입니다.
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)
명확한 설명을 위해 승인된 답변에 댓글을 달기(댓글을 추가하기에 충분한 카르마가 없음)
procedure analyze()는 지정된 열의 데이터 집합을 분석하고 최적의 데이터 유형을 제안하는 다른 목적을 위한 것입니다. 즉, varchar(255) 행이 1000개이고 varchar(23)가 실제로 얼마나 필요한지 확인하고자 할 때 유용합니다. 예를 들어 varchar(23)로 충분하다는 것을 알려줄 수도 있습니다.
2020년 업데이트EXPLAIN ANALYZE이용할 수 있는
오래된 질문이지만 버전이 포함된 업데이트를 위한 것입니다.8.0.18 Analyze 설명은 다음에서도 사용할 수 있습니다.MySQL아래와 같이 사용할 수 있습니다.
mysql> explain analyze select count(*) from sbtest1 where k > 500000\G
*************************** 1. row ***************************
EXPLAIN: -> Aggregate: count(0) (actual time=178.225..178.225 rows=1 loops=1)
-> Filter: (sbtest1.k > 500000) (cost=98896.53 rows=493204) (actual time=0.022..147.502 rows=625262 loops=1)
-> Index range scan on sbtest1 using idx3 (cost=98896.53 rows=493204) (actual time=0.021..96.488 rows=625262 loops=1)
1 row in set (0.18 sec)
언급URL : https://stackoverflow.com/questions/6812655/what-is-the-mysql-equivalent-of-postgresqls-explain-analyze
'programing' 카테고리의 다른 글
| C에서 "==" 연산자의 반환 값 (0) | 2023.09.11 |
|---|---|
| 부모 구성 요소의 angular2 호출 함수 (0) | 2023.09.11 |
| php 5.6에서 mariadb 10.1에 삽입 일부 행을 삽입하지 않음 (0) | 2023.09.11 |
| CSS 호버 이벤트에서 다른 디브의 스타일링을 변경할 수 있습니까? (0) | 2023.09.06 |
| jQuery bind to Paste Event, 붙여넣기 내용을 가져오는 방법 (0) | 2023.09.06 |