读《高性能MySQL》第三版,笔记。
官方文档:https://dev.mysql.com/doc/refman/5.7/en/show-profile.html

使用 SHOW PROFILE

 set profiling = 1;show profiles;show profile for query 1;

使用 help 命令查看说明:

mysql> help show profile
Name: 'SHOW PROFILE'
Description:
Syntax:
SHOW PROFILE [type [, type] ... ][FOR QUERY n][LIMIT row_count [OFFSET offset]]type:ALL| BLOCK IO| CONTEXT SWITCHES| CPU| IPC| MEMORY| PAGE FAULTS| SOURCE| SWAPSThe SHOW PROFILE and SHOW PROFILES statements display profiling
information that indicates resource usage for statements executed
during the course of the current session.*Note*:These statements are deprecated and will be removed in a future MySQL
release. Use the Performance Schema instead; see
http://dev.mysql.com/doc/refman/5.7/en/performance-schema-query-profili
ng.html.Profiling is controlled by the profiling session variable, which has a
default value of 0 (OFF). Profiling is enabled by setting profiling to
1 or ON:mysql> SET profiling = 1;SHOW PROFILES displays a list of the most recent statements sent to the
server. The size of the list is controlled by the
profiling_history_size session variable, which has a default value of
15. The maximum value is 100. Setting the value to 0 has the practical
effect of disabling profiling.All statements are profiled except SHOW PROFILE and SHOW PROFILES, so
you will find neither of those statements in the profile list.
Malformed statements are profiled. For example, SHOW PROFILING is an
illegal statement, and a syntax error occurs if you try to execute it,
but it will show up in the profiling list.SHOW PROFILE displays detailed information about a single statement.
Without the FOR QUERY n clause, the output pertains to the most
recently executed statement. If FOR QUERY n is included, SHOW PROFILE
displays information for statement n. The values of n correspond to the
Query_ID values displayed by SHOW PROFILES.The LIMIT row_count clause may be given to limit the output to
row_count rows. If LIMIT is given, OFFSET offset may be added to begin
the output offset rows into the full set of rows.By default, SHOW PROFILE displays Status and Duration columns. The
Status values are like the State values displayed by SHOW PROCESSLIST,
although there might be some minor differences in interpretion for the
two statements for some status values (see
http://dev.mysql.com/doc/refman/5.7/en/thread-information.html).Optional type values may be specified to display specific additional
types of information:o ALL displays all informationo BLOCK IO displays counts for block input and output operationso CONTEXT SWITCHES displays counts for voluntary and involuntarycontext switcheso CPU displays user and system CPU usage timeso IPC displays counts for messages sent and receivedo MEMORY is not currently implementedo PAGE FAULTS displays counts for major and minor page faultso SOURCE displays the names of functions from the source code, togetherwith the name and line number of the file in which the functionoccurso SWAPS displays swap countsProfiling is enabled per session. When a session ends, its profiling
information is lost.URL: http://dev.mysql.com/doc/refman/5.7/en/show-profile.htmlExamples:
mysql> SELECT @@profiling;
+-------------+
| @@profiling |
+-------------+
|           0 |
+-------------+
1 row in set (0.00 sec)mysql> SET profiling = 1;
Query OK, 0 rows affected (0.00 sec)mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec)mysql> SHOW PROFILES;
+----------+----------+--------------------------+
| Query_ID | Duration | Query                    |
+----------+----------+--------------------------+
|        0 | 0.000088 | SET PROFILING = 1        |
|        1 | 0.000136 | DROP TABLE IF EXISTS t1  |
|        2 | 0.011947 | CREATE TABLE t1 (id INT) |
+----------+----------+--------------------------+
3 rows in set (0.00 sec)mysql> SHOW PROFILE;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| checking permissions | 0.000040 |
| creating table       | 0.000056 |
| After create         | 0.011363 |
| query end            | 0.000375 |
| freeing items        | 0.000089 |
| logging slow query   | 0.000019 |
| cleaning up          | 0.000005 |
+----------------------+----------+
7 rows in set (0.00 sec)mysql> SHOW PROFILE FOR QUERY 1;
+--------------------+----------+
| Status             | Duration |
+--------------------+----------+
| query end          | 0.000107 |
| freeing items      | 0.000008 |
| logging slow query | 0.000015 |
| cleaning up        | 0.000006 |
+--------------------+----------+
4 rows in set (0.00 sec)mysql> SHOW PROFILE CPU FOR QUERY 2;
+----------------------+----------+----------+------------+
| Status               | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| checking permissions | 0.000040 | 0.000038 |   0.000002 |
| creating table       | 0.000056 | 0.000028 |   0.000028 |
| After create         | 0.011363 | 0.000217 |   0.001571 |
| query end            | 0.000375 | 0.000013 |   0.000028 |
| freeing items        | 0.000089 | 0.000010 |   0.000014 |
| logging slow query   | 0.000019 | 0.000009 |   0.000010 |
| cleaning up          | 0.000005 | 0.000003 |   0.000002 |
+----------------------+----------+----------+------------+
7 rows in set (0.00 sec)

栗子

使用 world 数据库 为例:

mysql> set profiling = 1;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> select max(id) from city;
+---------+
| max(id) |
+---------+
|    4079 |
+---------+
1 row in set (0.00 sec)
mysql>  show profiles;
+----------+------------+--------------------------+
| Query_ID | Duration   | Query                    |
+----------+------------+--------------------------+
|        1 | 0.00019075 | select max(id) from city |
+----------+------------+--------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> show profile for query 1;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000054 |
| checking permissions | 0.000005 |
| Opening tables       | 0.000015 |
| init                 | 0.000019 |
| System lock          | 0.000009 |
| optimizing           | 0.000029 |
| executing            | 0.000008 |
| end                  | 0.000002 |
| query end            | 0.000006 |
| closing tables       | 0.000012 |
| freeing items        | 0.000026 |
| cleaning up          | 0.000007 |
+----------------------+----------+
12 rows in set, 1 warning (0.01 sec)

MySQL 解析单条查询相关推荐

  1. Mysql剖析单条查询三种方法

    三种方法: SHOW PROFILE SHOW STATUE 检查慢查询日志 SHOW PROFILE能帮助我们定位到哪些活动花费了最多的时间,但并不会告诉我们为什么会这样. SHOW STATUE是 ...

  2. 步步深入MySQL:架构-查询执行流程-SQL解析顺序

    一.前言 一直是想知道一条SQL语句是怎么被执行的,它执行的顺序是怎样的,然后查看总结各方资料,就有了下面这一篇博文了. 本文将从MySQL总体架构--->查询执行流程--->语句执行顺序 ...

  3. MySQL多表查询全面解析实例【汇总】

    经常遇到mysql多表查询的问题,特整理关于MySQL多表查询全面解析实例分享记录.一步一步实战MySQL多表查询. 创建虚拟数据 -- [创建公司职员表] --DROP TABLE IF EXIST ...

  4. MySQL 架构总览-查询执行流程-SQL 解析顺序

    点击关注公众号,回复"1024"获取2TB学习资源! 前言 一直是想知道一条 SQL 语句是怎么被执行的,它执行的顺序是怎样的,然后查看总结各方资料,就有了下面这一篇博文了. 本文 ...

  5. java mysql 多表查询_解析Mysql多表查询的实现

    查询是数据库的核心,下面就为您介绍Mysql多表查询时如何实现的,如果您在Mysql多表查询方面遇到过问题,不妨一看. Mysql多表查询: CREATE TABLE IF NOT EXISTS co ...

  6. mysql教程多表查询_解析Mysql多表查询的实现

    查询是数据库的核心,下面就为您介绍Mysql多表查询时如何实现的,如果您在Mysql多表查询方面遇到过问题,不妨一看. Mysql多表查询: CREATE TABLE IF NOT EXISTS co ...

  7. mysql笔记03 查询性能优化

    查询性能优化 1. 为什么查询速度会慢? 1). 如果把查询看作是一个任务,那么它由一系列子任务组成,每个子任务都会消耗一定的时间.如果要优化查询,实际上要优化其子任务,要么消除其中一些子任务,要么减 ...

  8. mysql 执行查询_MySQL查询的执行过程

    我们总是希望MySQL能够获得更高的查询性能,最好的办法是弄清楚MySQL是如何优化和执行查询的.一旦理解了这一点,就会发现:很多的查询优化工作实际上就是遵循一些原则让MySQL的优化器能够按照预想的 ...

  9. Mysql多表查询效率的研究(一)

    Mysql多表查询效率的研究(一) 本文探究了mysql InnoDB引擎在多表查询的应用场景下,使用子表.内连接和左联接运行速度的差别,并且比较了索引使用与否对查询效率的影响. 第一部分简略地概括了 ...

最新文章

  1. 《高级无线网络—4G技术》——1.3 混合4G无线网络协议
  2. 简述hdfs工作原理_hdfs工作机制和原理 简述hdfs的原理
  3. 使用百度云服务器BCC搭建网站,过程记录
  4. 前端关系图谱插件_智游告诉你,前端开发应该学什么?
  5. 如何开发一款高大上的android应用的必备知识
  6. 考研天勤 数据结构 图(自用回顾)
  7. sas 安装后处理出错
  8. 2019冬季乙级考试
  9. 解决Win10磁盘占用100%
  10. 运算符和强制类型转换
  11. 24岁想学插画来得及吗?零基础学插画需要了解这些
  12. Flex自定义鼠标右键
  13. 程序员之问——为什么聊天软件app大多采用绿色?
  14. 【CMake 语法】(6) CMake 条件、循环、跳出循环
  15. 中芯微761的随身WiFi怎么切卡去除后门
  16. 2015在大型多人在线游戏市场报告
  17. 版署:近期将清理所有未经审查进口游戏
  18. oracle关键字 转译,ORACLE中ESCAPE关键字用法 换字符用法
  19. 捕获计算机屏幕++方法,在Win10中获取屏幕截图的五大方法
  20. 平面设计新手需要注意哪些误区

热门文章

  1. w7电脑蓝屏怎么解决_电脑蓝屏,教您电脑蓝屏怎么办
  2. 串口传输 波特率 延时时间的设置
  3. 一种高精度低功耗NB-IoT温度传感器
  4. sadp 2011错误_2011年最危险的25个软件错误
  5. 网络工程师在现实中的意义
  6. BACnet协议详解——应用层说明二
  7. 功能机和Andorid 语言支持
  8. 【单片机系列】基于51单片机的16路抢答器
  9. 蓝桥 迷宫寻宝 记忆化搜索
  10. js:js中加载js文件