Skip to content

Instantly share code, notes, and snippets.

@matsuu
Last active November 23, 2023 13:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuu/8dde4ba0eebbeefe9db1c308b343b765 to your computer and use it in GitHub Desktop.
Save matsuu/8dde4ba0eebbeefe9db1c308b343b765 to your computer and use it in GitHub Desktop.
performance_schemaを使用したスロークエリー抽出
-- ORDER BYとLIMITは必要応じて適宜修正
-- VIEWを作成すると便利
SELECT
count_star AS cnt,
sum_timer_wait/1e12 AS sum,
min_timer_wait/1e12 AS min,
avg_timer_wait/1e12 AS avg,
max_timer_wait/1e12 AS max,
sum_rows_sent AS sumRows,
sum_rows_sent/count_star AS avgRows,
schema_name AS db,
digest_text AS query
FROM performance_schema.events_statements_summary_by_digest
ORDER BY sum DESC
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment