写点什么

mysql 优化之 performance Schema 常用查询 sql

作者:@下一站
  • 2022-12-05
    陕西
  • 本文字数:1256 字

    阅读完需:约 4 分钟

mysql优化之 performance Schema常用查询sql
use `performance_schema`
复制代码


--1、哪类的 SQL 执行最多?


SELECT  DIGEST_TEXT,  COUNT_STAR,  FIRST_SEEN,  LAST_SEENFROM  events_statements_summary_by_digestORDER BY  COUNT_STAR DESC
复制代码


--2、哪类 SQL 的平均响应时间最多?


SELECT  DIGEST_TEXT,  AVG_TIMER_WAITFROM  events_statements_summary_by_digestORDER BY  COUNT_STAR DESC
复制代码


-3、哪类 SQL 排序记录数最多?


SELECT  DIGEST_TEXT,  SUM_SORT_ROWSFROM  events_statements_summary_by_digestORDER BY  COUNT_STAR DESC
复制代码


-4、哪类 SQL 扫描记录数最多?


SELECT  DIGEST_TEXT,  SUM_ROWS_EXAMINEDFROM  events_statements_summary_by_digestORDER BY  COUNT_STAR DESC
复制代码


--5、哪类 SQL 使用临时表最多?


SELECT  DIGEST_TEXT,  SUM_CREATED_TMP_TABLES,  SUM_CREATED_TMP_DISK_TABLESFROM  events_statements_summary_by_digestORDER BY  COUNT_STAR DESC
复制代码


--6、哪类 SQL 返回结果集最多?


SELECT  DIGEST_TEXT,  SUM_ROWS_SENTFROM  events_statements_summary_by_digestORDER BY  COUNT_STAR DESC
复制代码


--7、哪个表物理 IO 最多?


SELECT  file_name,  event_name,  SUM_NUMBER_OF_BYTES_READ,  SUM_NUMBER_OF_BYTES_WRITEFROM  file_summary_by_instanceORDER BY  SUM_NUMBER_OF_BYTES_READ + SUM_NUMBER_OF_BYTES_WRITE DESC
复制代码


--8、哪个表逻辑 IO 最多?


SELECT  object_name,  COUNT_READ,  COUNT_WRITE,  COUNT_FETCH,  SUM_TIMER_WAITFROM  table_io_waits_summary_by_tableORDER BY  sum_timer_wait DESC
复制代码


--9、哪个索引访问最多?


SELECT  OBJECT_NAME,  INDEX_NAME,  COUNT_FETCH,  COUNT_INSERT,  COUNT_UPDATE,  COUNT_DELETEFROM  table_io_waits_summary_by_index_usageORDER BY  SUM_TIMER_WAIT DESC
复制代码


--10、哪个索引从来没有用过 ?


SELECT  OBJECT_SCHEMA,  OBJECT_NAME,  INDEX_NAMEFROM  table_io_waits_summary_by_index_usageWHERE  INDEX_NAME IS NOT NULLAND COUNT_STAR = 0AND OBJECT_SCHEMA <> 'mysql'ORDER BY  OBJECT_SCHEMA,OBJECT_NAME;
复制代码


--11、哪个等待事件消耗时间最多?



SELECT EVENT_NAME, COUNT_STAR, SUM_TIMER_WAIT, AVG_TIMER_WAITFROM events_waits_summary_global_by_event_nameWHERE event_name != 'idle'ORDER BY SUM_TIMER_WAIT DESC
复制代码


--12-1、剖析某条 SQL 的执行情况,包括 statement 信息,stege 信息,wait 信息


SELECT  EVENT_ID,  sql_textFROM  events_statements_historyWHERE  sqL_text LIKE '%count(*)%';
复制代码


--12 - 2、查看每个阶段的时间消耗



SELECT event_id, EVENT_NAME, SOURCE, TIMER_END - TIMER_STARTFROM events_stages_history_longWHERE NESTING_EVENT_ID = 1553
复制代码


--12 - 3、查看每个阶段的锁等待情况


SELECT  event_id,  event_name,  source,  timer_wait,  object_name,  index_name,  operation,  nesting_event_idFROM  events_waits_history_longWHERE  nesting_event_id = 1553
复制代码


发布于: 16 小时前阅读数: 15
用户头像

@下一站

关注

懒人 2020-11-22 加入

都是黄泉预约客,何必难为每一天,执念太强,无法豁然。

评论

发布
暂无评论
mysql优化之 performance Schema常用查询sql_MySQL_@下一站_InfoQ写作社区