-- top_digests_now.sql: statements by total execution time since the digest table was last reset -- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/) -- https://hashjoin.com/kb/mysql/high-cpu-empty-slow-log/ -- -- Usage: mysql -t < top_digests_now.sql -- -- Sorted by total time, not time per call, which is what the slow query log can't do: a 2 ms -- query run 500 times a second costs a full CPU core and never shows up in the slow log. -- per_sec is averaged since the digest was first seen, so it smooths out bursts; for "what ran -- during the spike" take snapshots (awr-statement-digest-snapshots on this site). SELECT IFNULL(SCHEMA_NAME, '') AS schema_name, LEFT(DIGEST, 12) AS digest, COUNT_STAR AS calls, ROUND(COUNT_STAR / GREATEST(TIMESTAMPDIFF(SECOND, FIRST_SEEN, LAST_SEEN), 1), 1) AS per_sec, ROUND(SUM_TIMER_WAIT / 1e12, 1) AS total_sec, ROUND(SUM_TIMER_WAIT / NULLIF(COUNT_STAR, 0) / 1e9, 3) AS avg_ms, ROUND(MAX_TIMER_WAIT / 1e9, 1) AS max_ms, ROUND(SUM_ROWS_EXAMINED / NULLIF(COUNT_STAR, 0)) AS exam_per_call, ROUND(100 * SUM_TIMER_WAIT / SUM(SUM_TIMER_WAIT) OVER (), 1) AS pct_of_all, LEFT(REPLACE(DIGEST_TEXT, '\n', ' '), 70) AS statement FROM performance_schema.events_statements_summary_by_digest ORDER BY SUM_TIMER_WAIT DESC LIMIT 15;