Skip to content

Instantly share code, notes, and snippets.

@gugu
Created June 22, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugu/bbc0e45c92801a6abc29f1e6784dce42 to your computer and use it in GitHub Desktop.
Save gugu/bbc0e45c92801a6abc29f1e6784dce42 to your computer and use it in GitHub Desktop.
Slow log UI
SELECT q, COUNT(*) AS c, avg(query_time) as avg_query, avg(lock_time), COUNT(*) * AVG(query_time) as total_time
FROM (
SELECT regexp_replace(regexp_replace(regexp_replace(sql_text, "'.*?'", '?'), 'IN \\(.*?\\)', 'IN ?'), '\\d+', '?') as q, query_time, lock_time from mysql.slow_log
WHERE DATEDIFF(start_time, NOW()) < 30
) a
GROUP by q
ORDER BY total_time DESC
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment