Reading the slow log with pt-query-digest rather than by eye

The slow log ranks by individual duration, so a query taking two seconds once appears above one taking 40 milliseconds two hundred thousand times — and the second is the actual problem.

$ pt-query-digest /var/log/mysql/slow.log | head -30

# Rank Response time  Calls   R/Call  Item
# ==== ============== ======= ======= ===================
#    1 812.4s  41.2%  201441  0.0040  SELECT order_lines
#    2 402.1s  20.4%       3  134.03  SELECT reports
#    3 188.9s   9.6%   14204  0.0133  SELECT customers

$ SET GLOBAL long_query_time = 0.05;   # and log_queries_not_using_indexes

Ranking by total time rather than per-call is the whole point, and it groups by normalised query so the same statement with different literals is one row. Lowering long_query_time to fifty milliseconds during an investigation is what makes the log useful — the default of ten seconds logs almost nothing on a healthy system. Turning it back up afterwards matters, because the log is a write on every slow query.