-------+--------------+-----------+---------------+---------------+------------+ -- | user | total | total_latency | max_latency | lock_latency | rows_sent | rows_examined | rows_affected | full_scans | -- +------+-------+---------------+-------------+--------------+-----------+---------------+---------------+------------+ -- | root | 3381 | 00:02:09.13 | 1.48 s | 1.07 s | 1151 | 93947 | 150 | 91 | -- +------+-------+---------------+-------------+--------------+-----------+---------------+---------------+------------+ -- CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary_by_statement_latency ( user, total, total_latency, max_latency, lock_latency, cpu_latency, rows_sent, rows_examined, rows_affected, full_scans ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUM(count_star) AS total, format_pico_time(SUM(sum_timer_wait)) AS total_latency, format_pico_time(SUM(max_timer_wait)) AS max_latency, format_pico_time(SUM(sum_lock_time)) AS lock_latency, format_pico_time(SUM(sum_cpu_time)) AS cpu_latency, SUM(sum_rows_sent) AS rows_sent, SUM(sum_rows_examined) AS rows_examined, SUM(sum_rows_affected) AS rows_affected, SUM(sum_no_index_used) + SUM(sum_no_good_index_used) AS full_scans FROM performance_schema.events_statements_summary_by_user_by_event_name GROUP BY IF(user IS NULL, 'background', user) ORDER BY SUM(sum_timer_wait) DESC;