31장. EXPLAIN ANALYZE 실전 판독
고객 1842의 최근 주문 20건이라는 같은 query를 평균 고객과 skew 고객으로 실행한다. TREE format에서 estimated rows, actual rows/loops, access type, chosen key, attached condition을 본다.
explain analyze
select id,status,gross_amount,created_at
from orders
where customer_id=1842
order by created_at desc,id desc
limit 20;
rows examined / rows sent가 높은지, filesort의 input 크기, secondary index에서 clustered PK lookup 횟수를 본다. Using filesort라는 단어만으로 실패 판정하지 않는다. 작은 result의 in-memory sort가 더 싼 경우도 있다.
histogram은 skew를 알리는 도구지 index를 대신하지 않는다. statistics 갱신 전후 plan과 plan stability를 본다. 수정 후 insert/update p95, buffer pool, redo bytes, replica lag, index size를 함께 측정한다.