18 Show Profile

查看Profile是否开启

mysql> show variables like 'profiling';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| profiling     | OFF   |
+---------------+-------+
1 row in set

# 如关闭,则开启
mysql> set profiling = on;
Query OK, 0 rows affected


mysql> show variables like 'profiling';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| profiling     | ON    |
+---------------+-------+
1 row in set

分析Profile

# 首先执行几条SQL

# 查看Profiles
mysql> show profiles;
+----------+------------+-------------------------------------+
| Query_ID | Duration   | Query                               |
+----------+------------+-------------------------------------+
|        1 |    9.75E-5 | like                                |
|        2 | 0.00042825 | show variables like 'profiling'     |
|        3 | 0.08572125 | select * from a                     |
|        4 |  1.8947365 | select * from do                    |
|        5 |  0.0015365 | select * from t_wechat_customer_msg |
|        6 | 8.02308925 | select * from do group by rand()    |
+----------+------------+-------------------------------------+
6 rows in set

# 分析耗时较少的select查询
mysql> show profile cpu,block io for query 5;
+----------------------+----------+----------+------------+--------------+---------------+
| Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting             | 4.2E-5   | 0        | 0          | NULL         | NULL          |
| checking permissions | 5E-6     | 0        | 0          | NULL         | NULL          |
| Opening tables       | 0.001203 | 0        | 0          | NULL         | NULL          |
| System lock          | 9E-6     | 0        | 0          | NULL         | NULL          |
| init                 | 1.2E-5   | 0        | 0          | NULL         | NULL          |
| optimizing           | 5E-6     | 0        | 0          | NULL         | NULL          |
| statistics           | 6E-6     | 0        | 0          | NULL         | NULL          |
| preparing            | 6E-6     | 0        | 0          | NULL         | NULL          |
| executing            | 1E-6     | 0        | 0          | NULL         | NULL          |
| Sending data         | 4.4E-5   | 0        | 0          | NULL         | NULL          |
| end                  | 3E-6     | 0        | 0          | NULL         | NULL          |
| query end            | 3E-6     | 0        | 0          | NULL         | NULL          |
| closing tables       | 5E-6     | 0        | 0          | NULL         | NULL          |
| freeing items        | 0.00019  | 0        | 0          | NULL         | NULL          |
| logging slow query   | 2E-6     | 0        | 0          | NULL         | NULL          |
| cleaning up          | 1E-6     | 0        | 0          | NULL         | NULL          |
+----------------------+----------+----------+------------+--------------+---------------+
16 rows in set


# 分析耗时较多的select查询
mysql> show profile cpu,block io for query 6;
+------------------------------+----------+----------+------------+--------------+---------------+
| Status                       | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+------------------------------+----------+----------+------------+--------------+---------------+
| starting                     | 6.6E-5   | 0        | 0          | NULL         | NULL          |
| checking permissions         | 8E-6     | 0        | 0          | NULL         | NULL          |
| Opening tables               | 0.001002 | 0        | 0          | NULL         | NULL          |
| System lock                  | 1.2E-5   | 0        | 0          | NULL         | NULL          |
| init                         | 1.4E-5   | 0        | 0          | NULL         | NULL          |
| optimizing                   | 4E-6     | 0        | 0          | NULL         | NULL          |
| statistics                   | 7E-6     | 0        | 0          | NULL         | NULL          |
| preparing                    | 8E-6     | 0        | 0          | NULL         | NULL          |
| Creating tmp table           | 5.8E-5   | 0        | 0          | NULL         | NULL          |
| executing                    | 3E-6     | 0        | 0          | NULL         | NULL          |
| Copying to tmp table         | 0.324864 | 0.327602 | 0          | NULL         | NULL          |
| converting HEAP to MyISAM    | 0.860471 | 0.858006 | 0          | NULL         | NULL          |
| Copying to tmp table on disk | 4.042798 | 4.009226 | 0.0156     | NULL         | NULL          |
| Sorting result               | 0.698543 | 0.452403 | 0.156001   | NULL         | NULL          |
| Sending data                 | 1.887769 | 0.436803 | 1.450809   | NULL         | NULL          |
| end                          | 8E-6     | 0        | 0          | NULL         | NULL          |
| removing tmp table           | 0.207213 | 0        | 0.0156     | NULL         | NULL          |
| end                          | 1.6E-5   | 0        | 0          | NULL         | NULL          |
| query end                    | 3E-6     | 0        | 0          | NULL         | NULL          |
| closing tables               | 7E-6     | 0        | 0          | NULL         | NULL          |
| freeing items                | 0.000215 | 0        | 0          | NULL         | NULL          |
| logging slow query           | 2E-6     | 0        | 0          | NULL         | NULL          |
| cleaning up                  | 2E-6     | 0        | 0          | NULL         | NULL          |
+------------------------------+----------+----------+------------+--------------+---------------+
23 rows in set


几种拖慢速度的Status

# converting HEAP to MyISAM
    查询结果太大,内存不够使用,要使用磁盘

# Copying to tmp table
    创建临时表
        1:创建临时表--Creating tmp table  
        2:拷贝数据到临时表--Copying to tmp table
        3:用完后删除临时表--removing tmp table   

# Copying to tmp table on disk
    把内存中的临时表复制到磁盘,会严重拖慢SQL执行速度

# locked
    锁表

profile几种参数类型

profile参数
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,347评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,260评论 25 709
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,054评论 6 342
  • 冬天的太阳是温柔的 它温柔的对待 使我不在害羞的躲在屋檐下 春天的细雨是忧愁的 它忧愁的述说 使我耐心的细细倾听它...
    4c385424e0da阅读 3,025评论 0 1
  • 高瓜小记 □ 陈昌龙 那天,微信群一个叫结林的加我为好友,自称...
    拙笔绘流年阅读 5,808评论 12 7