Chapter 12

Slow Query Analyzer

Slow Query Analysis

A systematic approach: enable slow log → aggregate with pt-query-digest → EXPLAIN → optimize → verify. This solves 90% of MySQL performance issues.

Enable Slow Log

SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 1;
SET GLOBAL log_queries_not_using_indexes = ON;

pt-query-digest

pt-query-digest --limit 20 /var/log/mysql/mysql-slow.log
pt-query-digest --processlist h=localhost,u=root,p=pass --interval 1

EXPLAIN Key Fields

EXPLAIN ANALYZE (8.0.18+)

Actually executes the query and shows actual vs estimated rows — reveals when optimizer statistics are stale.

Common Patterns

Rate this chapter
4.6  / 5  (31 ratings)

💬 Comments