Skip to content
gohacks.dev
Databases

MySQL Slow Query Log Analyzer

Summarise a MySQL slow query log: queries grouped by fingerprint and ranked by total time, with call counts, maximum time and rows examined per row sent.

Free · No sign-up · Your inputs stay in your browser

Input

Summarise a MySQL slow query log

Output

2 distinct queries

QueryCallsTotal sShareMax sExamined / sent
SELECT country, COUNT(*) FROM customers c JOIN orders o ON o.customer_id = c.id WHERE o.status IN (?+) GROUP BY country17.8863.5%7.8887,517
SELECT * FROM orders WHERE customer_email = ? ORDER BY created_at DESC LIMIT ?24.5236.5%2.40498,211

Queries are grouped by fingerprint, with literals replaced by ? and IN lists collapsed, the way pt-query-digest does, and ranked by total time: a 50 ms query run 10,000 times costs more than one 8-second report. Rows examined per row sent above a few hundred usually means a missing index.

Runs in this browser. Nothing you paste is sent to a server.

Turning the log on

Set slow_query_log = ON, long_query_time to a threshold in seconds (0.5 is a common start) and optionally log_queries_not_using_indexes. The log path is in slow_query_log_file. The slow query log documentation covers the options; managed services such as RDS expose it through parameter groups.

Rows examined per row sent

A query that examines 500,000 rows to return one is doing a scan where an index lookup should be. That ratio is often more useful than time, because time varies with load and the ratio does not.

Share

Frequently asked questions

What is pt-query-digest?
A tool from Percona Toolkit that reads slow logs, general logs or tcpdump captures and produces a ranked report of query fingerprints. This page does the core of it for a pasted excerpt.
Does the slow log slow MySQL down?
Slightly, mostly in disk writes. With a sensible long_query_time it is safe to leave on in production; setting it to 0 logs every query and is for short investigations only.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools