MySQL学习笔记之SQL语句执行过程查看
文章目录
- 参数使能
- 查看最近一条SQL执行过程
- 查看profiling打开开后,所有SQL语句执行耗时
- 查看某一条SQL的执行过程
- 指定要查看的性能选项
- 查看所有性能选项
参数使能
以select
语句为例,首先打开profile
参数:
mysql> set profiling = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
然后执行两边下面的语句:
mysql> select * from employees;
查看最近一条SQL执行过程
可以通过show profile
语句查看最近一条SQL的执行过程:
mysql> show profile;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000039 |
| checking permissions | 0.000004 |
| Opening tables | 0.000012 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000002 |
| statistics | 0.000008 |
| preparing | 0.000010 |
| executing | 0.000003 |
| Sending data | 0.000188 |
| end | 0.000004 |
| query end | 0.000006 |
| closing tables | 0.000008 |
| freeing items | 0.000104 |
| cleaning up | 0.000013 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)
可以看到一条SQL语句要经历上述15步。如果开启了SQL缓存且命中缓存的话,步骤会减少,但SQL缓存要求两条SQL必须完全一样才能命中,任何字符的更改(包括注释、空格等)都会导致缓存没命中,因此MySQL的缓存相当鸡肋,命中率很低。
查看profiling打开开后,所有SQL语句执行耗时
可以通过show profiles
开启profiling
后所有SQL语句的耗时:
mysql> show profiles;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 1 | 0.00070175 | select * from employees |
| 2 | 0.00041950 | select * from employees |
+----------+------------+-------------------------+
2 rows in set, 1 warning (0.00 sec)
查看某一条SQL的执行过程
可以通过show profile for query Query_ID
查看:
mysql> show profile for query 1;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000036 |
| checking permissions | 0.000004 |
| Opening tables | 0.000012 |
| init | 0.000013 |
| System lock | 0.000006 |
| optimizing | 0.000002 |
| statistics | 0.000008 |
| preparing | 0.000355 |
| executing | 0.000006 |
| Sending data | 0.000169 |
| end | 0.000003 |
| query end | 0.000005 |
| closing tables | 0.000006 |
| freeing items | 0.000070 |
| cleaning up | 0.000007 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)mysql> show profile for query 2;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000039 |
| checking permissions | 0.000004 |
| Opening tables | 0.000012 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000002 |
| statistics | 0.000008 |
| preparing | 0.000010 |
| executing | 0.000003 |
| Sending data | 0.000188 |
| end | 0.000004 |
| query end | 0.000006 |
| closing tables | 0.000008 |
| freeing items | 0.000104 |
| cleaning up | 0.000013 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)
指定要查看的性能选项
mysql> show profile CPU, block io;
+---------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+---------------+----------+----------+------------+--------------+---------------+
| starting | 0.000066 | 0.000000 | 0.000000 | NULL | NULL |
| freeing items | 0.000058 | 0.000000 | 0.000000 | NULL | NULL |
| cleaning up | 0.000004 | 0.000000 | 0.000000 | NULL | NULL |
+---------------+----------+----------+------------+--------------+---------------+
3 rows in set, 1 warning (0.00 sec)
查看所有性能选项
mysql> show profile all for query 1\G
*************************** 1. row ***************************Status: startingDuration: 0.000036CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: NULLSource_file: NULLSource_line: NULL
*************************** 2. row ***************************Status: checking permissionsDuration: 0.000004CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: check_accessSource_file: sql_authorization.ccSource_line: 802
*************************** 3. row ***************************Status: Opening tablesDuration: 0.000012CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: open_tablesSource_file: sql_base.ccSource_line: 5714
*************************** 4. row ***************************Status: initDuration: 0.000013CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: handle_querySource_file: sql_select.ccSource_line: 121
*************************** 5. row ***************************Status: System lockDuration: 0.000006CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_lock_tablesSource_file: lock.ccSource_line: 323
*************************** 6. row ***************************Status: optimizingDuration: 0.000002CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::optimizeSource_file: sql_optimizer.ccSource_line: 151
*************************** 7. row ***************************Status: statisticsDuration: 0.000008CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::optimizeSource_file: sql_optimizer.ccSource_line: 367
*************************** 8. row ***************************Status: preparingDuration: 0.000355CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::optimizeSource_file: sql_optimizer.ccSource_line: 475
*************************** 9. row ***************************Status: executingDuration: 0.000006CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::execSource_file: sql_executor.ccSource_line: 119
*************************** 10. row ***************************Status: Sending dataDuration: 0.000169CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::execSource_file: sql_executor.ccSource_line: 195
*************************** 11. row ***************************Status: endDuration: 0.000003CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: handle_querySource_file: sql_select.ccSource_line: 199
*************************** 12. row ***************************Status: query endDuration: 0.000005CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_execute_commandSource_file: sql_parse.ccSource_line: 4946
*************************** 13. row ***************************Status: closing tablesDuration: 0.000006CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_execute_commandSource_file: sql_parse.ccSource_line: 4998
*************************** 14. row ***************************Status: freeing itemsDuration: 0.000070CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_parseSource_file: sql_parse.ccSource_line: 5610
*************************** 15. row ***************************Status: cleaning upDuration: 0.000007CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: dispatch_commandSource_file: sql_parse.ccSource_line: 1924
15 rows in set, 1 warning (0.00 sec)
举其中的一行为例:*************************** 10. row ***************************Status: Sending dataDuration: 0.000169CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::execSource_file: sql_executor.ccSource_line: 195
每一行数据就显示该步骤下的各个阶段的耗时,甚至源文件等信息。
相关文章:

MySQL学习笔记之SQL语句执行过程查看
文章目录 参数使能查看最近一条SQL执行过程查看profiling打开开后,所有SQL语句执行耗时查看某一条SQL的执行过程指定要查看的性能选项查看所有性能选项 参数使能 以select语句为例,首先打开profile参数: mysql> set profiling 1; Query…...

如何以毫秒精度,查看系统时间以及文件的创建时间
用 cmd 查看系统的时间: powershell -command "(Get-Date -UFormat %Y-%m-%d %H:%M:%S).toString() . ((Get-Date).millisecond)" 用 XYplorer 查看文件的精确创建时间(含30天试用): XYplorer - File Manager for …...

基于机器学习的情绪识别算法matlab仿真,对比SVM,LDA以及决策树
目录 1.算法理论概述 2.部分核心程序 3.算法运行软件版本 4.算法运行效果图预览 5.算法完整程序工程 1.算法理论概述 情绪识别是一种重要的情感分析任务,旨在从文本、语音或图像等数据中识别出人的情绪状态,如高兴、悲伤、愤怒等。本文介绍一种基于…...

jMeter使用随记
参数化BodyData 先制作参数文件 再设置一个csv data set config 最后在body data里面写上参数${xxxxx}...

[语义分割] DeepLab v3(Cascaded model、ASPP model、两种ASPP对比、Multi-grid、训练细节)
Rethinking Atrous Convolution for Semantic Image Segmentation 论文地址:Rethinking Atrous Convolution for Semantic Image SegmentationPytorch 实现代码:pytorch_segmentation/deeplab_v3 这是一篇 2017 年发表在CVPR上的文章。相比 DeepLab V2 有…...

css - Media Query
使用bootstrap的grid system可以在一个较为粗糙的范围得到较好的响应性,但是通过viewport可以看到网站在具体哪个像素点处变得丑陋,再通过css media query来精细调整网页布局。 可以通过media query来提高网页移动响应能力。...

9.python设计模式【外观模式】
内容:为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一个子系统更加容易使用。 角色: 外观(facade)子类系统(subsystem classes) UML图 举…...

Webpack5 CopyPlugin的作用
在Webpack 5中,CopyPlugin是一个插件,用于将文件或目录从源位置复制到构建目录中。它的作用是帮助开发人员在构建过程中将静态文件(如图片、字体等)直接复制到输出目录,而无需经过任何处理。 CopyPlugin并不是必须的&…...

kafka服务端允许生产者发送最大消息体大小
1、kafka config服务端配置文件server.properties server.properties中加上的message.max.bytes配置,我目前设置为5242880,即5MB,可以根据实际情况增大。 message.max.bytes5242880 在生产者端配置max.request.size,这是单个消息…...

台阶型Nim游戏博弈论
台阶型Nim游戏 题目 https://www.acwing.com/problem/content/894/ 现在,有一个 n n n 级台阶的楼梯,每级台阶上都有若干个石子,其中第 i i i 级台阶上有 a i a_i ai 个石子( i ≥ 1 i \ge 1 i≥1)。 两位玩家轮流操作,每…...

NestJS 的 中间件 学习
基本概念 中间件是在路由处理程序之前调用的函数。中间件函数可以访问请求和响应对象。在程序中我们可以让多个中间件串起来一起使用,当多个中间件一起使用时我们可以使用next()调用下一个中间件。 中间件主要是可以实现如下功能: 执行任何代码更改请…...

搭建自己第一个golang程序
概念: golang 和 java有些类似,配置好环境就可以直接编写运行了;这里分两种: 一.shell模式 创建一个go类型的文件 往里面编写代码 二.开发工具模式 这里的开发工具 我选用goland package mainimport "fmt"func mai…...

Mysql加锁过程
1、背景 MySQL/InnoDB的加锁分析,一直是一个比较困难的话题。我在工作过程中,经常会有同事咨询这方面的问题。同时,微博上也经常会收到MySQL锁相关的私信,让我帮助解决一些死锁的问题。本文,准备就MySQL/InnoDB的加锁问…...

财经界杂志财经界杂志社财经界编辑部2023年第19期目录
《财经界》投稿邮箱:cnqikantg126.com(注明投稿“《财经界》”) ●崔编辑Q Q :695548262 微信号:f99832970 名刊名著_国内外名刊名著 财经名刊名著 李少鹏 ;王海蕴; 6-7 发改委专线 六方面发力 看中国经济形势,既要看准当…...

Linux常用命令——dpkg-split命令
在线Linux命令查询工具 dpkg-split Debian Linux中将大软件包分割成小包 补充说明 dpkg-split命令用来将Debian Linux中的大软件包分割成小软件包,它还能够将已分割的文件进行合并。 语法 dpkg-split(选项)(参数)选项 -S:设置分割后的每个小文件最…...

常见的二十种软件测试方法详解
一.单元测试(模块测试) 单元测试是对软件组成单元进行测试。其目的是检验软件组成单位的正确性。测试对象是:模块。 对模块进行测试,单独的一个模块测试,属于静态测试的一类 测试阶段:编码后或者编码前&…...

Python(一)
要做到坚韧不拔,最要紧的是坚持到底。——陀思妥耶夫斯基 2023 6 14~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --根据你自己的操作系统下载对应的。 -- pyhton 文档 --交互方式 使用的工具 --如何启动工具 -- 交互式方式一般在数据分析中…...

git pull无效,显示 * branch master -> FETCH_HEADAlready up to date. pull无效解决方法
报错情况 本地文件夹中删除文件后,git pull无效。显示如下: **** MINGW64 ~/****/haha (master) $ git pull origin master From https://gitee.com/****/haha* branch master -> FETCH_HEAD Already up to date.解决 方法一 命令…...

SK5代理与socks5代理
第一部分:SK5代理与socks5代理的原理与功能 SK5代理 SK5代理是一种加密代理技术,其工作原理主要包括以下几个关键步骤: 代理服务器接收客户端请求;客户端与代理服务器之间建立加密连接;代理服务器将客户端的请求转发…...

【【51单片机红外遥控小风车】】
51单片机红外遥控小风车 今天结束了51单片机的学习,明天开始学习stm32 我是学习江科大的视频一步一步完成的 ,他讲的非常好,非常好 特别通俗易懂 学习复刻他的作品我也自己创作了一些 但是现在暂时脱离这块板子了 以后可能会更新一个应用51单…...

如何连接远程服务器?快解析内内网穿透可以吗?
如今我们迎来了数字化转型的时代,众多企业来为了更好地推动业务的发展,常常需要在公司内部搭建一个远程服务器。然而,对于企业员工来说,在工作过程中经常需要与这个服务器进行互动,而服务器位于公司的局域网中…...

【云边有个小卖部】上新《探秘Linux》第三章 Linux 软件包管理器 yum
🕺作者: 主页 我的专栏C语言从0到1C初阶C进阶数据结构从0到1探秘Linux菜鸟刷题集 😘欢迎关注:👍点赞🙌收藏✍️留言 🏇码字不易,你的👍点赞🙌收藏❤️关注对我…...

【深度学习】【Image Inpainting】Free-Form Image Inpainting with Gated Convolution
模型:DeepFillv2 (CVPR’2019) 论文:https://arxiv.org/abs/1806.03589 代码:https://github.com/JiahuiYu/generative_inpainting 文章目录 效果AbstractIntroductionRelated WorkAutomatic Image InpaintingGuided Image Inpainting and Sy…...

游戏引擎UE如何革新影视行业?创意云全面支持UE云渲染
虚幻引擎UE(Unreal Engine)作为一款“殿堂级”的游戏引擎,占据了全球80%的商用游戏引擎市场,但如果仅仅将其当做游戏开发的工具,显然是低估了它的能力。比如迪士尼出品的电视剧《曼达洛人》、电影《狮子王》等等都使用…...

DB-GPT:强强联合Langchain-Vicuna的应用实战开源项目,彻底改变与数据库的交互方式
今天看到 蚂蚁科技 Magic 开源的DB-GPT项目,觉得创意很好,集成了当前LLM的主流技术,主要如下 Langchain: 构建在LLM之上的应用开发框架HuggingFace: 模型标准,提供大模型管理功能Vicuna: 一个令GPT-4惊艳的开源聊天机…...

STM32CubeMX v6.9.0 BUG:FLASH_LATENCY设置错误导致初始化失败
背景 今天在调试外设功能时,发现设置了使用外部时钟之后程序运行异常,进行追踪调试并与先前可以正常运行的项目进行对比之后发现这个问题可能是由于新版本的STM32CubeMX配置生成代码时的BUG引起的。 测试环境 MCU: STM32H750VBT6 STM32CubeIDE: Versi…...

K8s-资源管理(二)
文章目录 2. 资源管理2.1 资源管理介绍2.2 YAML语言介绍2.3 资源管理方式2.3.1 命令式对象管理2.3.2 命令式对象配置2.3.3 声明式对象配置 2.4. 模拟使用普通用户来操作2.5 kubectl 一些基本命令2.6 使用个人的 docker 仓库的镜像 2. 资源管理 2.1 资源管理介绍 在kubernetes…...

脉冲信号测试应如何选择示波器带宽?
示波器模拟带宽的定义大家都比较熟悉,是针对于正弦波信号定义的。从频域上看,正弦波信号的频谱就是单根谱线,只要示波器的带宽不小于信号的频率,那么就可以有效观测到波形。若要追求更高的幅度测试精度,则可以按照5倍法…...

OpenCV DNN模块推理YOLOv5 ONNX模型方法
文章目录 概述1. 环境部署YOLOv5算法ONNX模型获取opencv-python模块安装 2.关键代码2.1 模型加载2.2 图片数据预处理2.3 模型推理2.4 推理结果后处理2.4.1 NMS2.4.2 score_threshold过滤2.4.3 bbox坐标转换与还原 3. 示例代码(可运行)3.1 未封装3.2 封装成类调用 概述 本文档主…...

ThirdAI 的私有和可个性化神经数据库:增强检索增强生成(第 3/3 部分)
这是我们关于使用检索增强生成构建 AI 代理的系列的最后一章 (3/3)。在第 1/3 部分中,我们讨论了断开连接的嵌入和基于矢量的检索管道的局限性。在第 2/3 部分中,我们介绍了神经数据库,它消除了存储和操作繁重且昂贵的…...