애플리케이션 개발/SQL

[SQL] explain

sofiaaa 2022. 5. 17. 15:36
반응형

 쿼리가 느리거나 성능을 향상 시키기 위해서 가장 먼저 보는 것은 explain이다.  

사용 방법으로는 주로 EXPLAIN SELECT * FROM TABLE WHERE 1 = 1 이런 식으로 사용한다.

 

explain을 사용하면 다음과 같은 정보를 얻을 수 있다.

구분 설명
id select 아이디로 SELECT를 구분하는 번호
table 참조하는 테이블
select_type select에 대한 타입
type 조인 혹은 조회 타입
possible_keys 데이터를 조회할 때 DB에서 사용할 수 있는 인덱스 리스트
key 실제로 사용할 인덱스
key_len 실제로 사용할 인덱스의 길이
ref Key 안의 인덱스와 비교하는 컬럼(상수)
rows 쿼리 실행 시 조사하는 행 수립
extra 추가 정보

 

https://dev.mysql.com/doc/refman/8.0/en/explain-output.html#explain_key

 

MySQL :: MySQL 8.0 Reference Manual :: 8.8.2 EXPLAIN Output Format

8.8.2 EXPLAIN Output Format The EXPLAIN statement provides information about how MySQL executes statements. EXPLAIN works with SELECT, DELETE, INSERT, REPLACE, and UPDATE statements. EXPLAIN returns a row of information for each table used in the SELECT s

dev.mysql.com

https://nomadlee.com/mysql-explain-sql/

 

MySQL Explain 실행계획 사용법 및 분석 - Useful Guide

mysql explain, explain 보는법, explain 사용법, select_type type, sub query, where 조건, 서브쿼리, 묵시적 형변환, like 검색, 최적화, type, filtered, type, key_len

nomadlee.com

 

반응형