使用performance_schema解决常见的故障案例
1 检查sql语句
使用performance_schema很容易找到引起性能问题的查询以及原因。
要启动语句检测,需要启动statement类型的插装。
插装类:
- statement/sql sql语句,如select,或者create table。
- statement/sp,存储过程
- statement/scheduler 事件调度器。
- statement/com 命令:如quit,kill,drop database,binlog dump,有些命令使用户不可用的只能mysqld调用。
- statement/abstract clone,query,new packet,relay log
2 常规sql语句
‘performance_schema将语句指标存储在
events_statement_current
events_statement_history
events_statement_history_long
SELECT a.*, c.thread_id, c.sql_text from information_schema.processlist a
LEFT JOIN performance_schema.threads b on a.id = b.PROCESSLIST_ID
LEFT JOIN performance_schema.events_statements_current c on c.THREAD_ID = b.THREAD_ID;
表中,表具有相同的结构。
3 可用于查询的优化指标列
created_tmp_disk_tables:查询创建临时表的数量,优化查询或者增加内存临死表的大小。
created_tmp_tables
mysql> select CREATED_TMP_DISK_TABLES, CREATED_TMP_TABLES from performance_schema.events_statements_hi
story;
+-------------------------+--------------------+
| CREATED_TMP_DISK_TABLES | CREATED_TMP_TABLES |
+-------------------------+--------------------+
| 0 | 0 |
| 0 | 0 |
| 0 | 1 |
| 0 | 1 |
| 0 | 0 |
+-------------------------+--------------------+
5 rows in set (0.01 sec)
select_full_join
select_FULL_RANGE_JOIN
SELECT RANGE
SELECT RANGE CHECK
SELECT SCAN
4 SYS用户下的核心statements视图
查找需要优化的视图