TIL

10.3(3) 실행 계획 분석 (type)

10.3.5 type 칼럼

system

const

eq_ref

id select_type table type key rows
1 SIMPLE de ref PRIMARY 165571
1 SIMPLE e eq_ref PRIMARY 1

ref

const, eq_ref, ref는 매우 좋은 접근 방법이므로 인덱스 분포도가 나쁘지 않다면 성능 문제를 일으키지 않는다. 쿼리 튜닝 시 이 세 가지에 대해서는 크게 신경쓰지 않아도 무방하다.

fulltext

EXPLAIN SELECT *
FROM employee_name
WHERE emp_no BETWEEN 10001 AND 10005
	AND MATCH(first_name, last_name) AGAINST('Facello' IN BOOLEAN MODE);
id select_type table type key Extra
1 SIMPLE employee_name fulltext fx_name Using where; ft_hints: no_ranking

ref_or_null

EXPLAIN SELECT * FROM titles
WHERE to_date='1985-03-01' OR to_date IS NULL;
id select_type table type key key_len ref rows
1 SIMPLE titles ref_or_null ix_todate 4 const 2

unique_subquery

EXPLAIN SELECT * FROM departments
WHERE dept_no IN 
	(SELECT dept_no FROM dept_emp WHERE emp_no=10001);
id select_type table type key key_len
1 PRIMARY departments index ux_deptnae 162
2 DEPENDENT SUBQUERY dept_emp unique_subquery PRIMARY 20

MySQL 8.0 버전에는 세미 조인 최적화 기능이 많이 도입되었기 때문에 실제로는 더 최적화된 실행 계획이 보일 것이다. unique_subquery와 index_subquery 설멍에서 사용된 실행 계획은 semijoin 최적화 옵션을 비활성화한 항태에서 만들어진 실행 계획이다.

index_subquery

range

EXPLAIN SELECT * FROM employees
WHERE emp_no BETWEEN 10002 AND 10004

index_merge

EXPLAIN SELECT * FROM employees
WHERE emp_no BETWEEN 10001 AND 11000
	OR first_name='Smith';
id type key key_len Extra
1 index_merge PRIMARY, ix_firstname 4, 58 Using union(PRIMARY, ix_firstname); Using where

index

ALL