当前位置: 首页 > news >正文

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单…...

三维GIS开发cesium智慧地铁教程(5)Cesium相机控制

一、环境搭建 <script src"../cesium1.99/Build/Cesium/Cesium.js"></script> <link rel"stylesheet" href"../cesium1.99/Build/Cesium/Widgets/widgets.css"> 关键配置点&#xff1a; 路径验证&#xff1a;确保相对路径.…...

shell脚本--常见案例

1、自动备份文件或目录 2、批量重命名文件 3、查找并删除指定名称的文件&#xff1a; 4、批量删除文件 5、查找并替换文件内容 6、批量创建文件 7、创建文件夹并移动文件 8、在文件夹中查找文件...

《Playwright:微软的自动化测试工具详解》

Playwright 简介:声明内容来自网络&#xff0c;将内容拼接整理出来的文档 Playwright 是微软开发的自动化测试工具&#xff0c;支持 Chrome、Firefox、Safari 等主流浏览器&#xff0c;提供多语言 API&#xff08;Python、JavaScript、Java、.NET&#xff09;。它的特点包括&a…...

Auto-Coder使用GPT-4o完成:在用TabPFN这个模型构建一个预测未来3天涨跌的分类任务

通过akshare库&#xff0c;获取股票数据&#xff0c;并生成TabPFN这个模型 可以识别、处理的格式&#xff0c;写一个完整的预处理示例&#xff0c;并构建一个预测未来 3 天股价涨跌的分类任务 用TabPFN这个模型构建一个预测未来 3 天股价涨跌的分类任务&#xff0c;进行预测并输…...

江苏艾立泰跨国资源接力:废料变黄金的绿色供应链革命

在华东塑料包装行业面临限塑令深度调整的背景下&#xff0c;江苏艾立泰以一场跨国资源接力的创新实践&#xff0c;重新定义了绿色供应链的边界。 跨国回收网络&#xff1a;废料变黄金的全球棋局 艾立泰在欧洲、东南亚建立再生塑料回收点&#xff0c;将海外废弃包装箱通过标准…...

C++ 求圆面积的程序(Program to find area of a circle)

给定半径r&#xff0c;求圆的面积。圆的面积应精确到小数点后5位。 例子&#xff1a; 输入&#xff1a;r 5 输出&#xff1a;78.53982 解释&#xff1a;由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982&#xff0c;因为我们只保留小数点后 5 位数字。 输…...

OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别

OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别 直接训练提示词嵌入向量的核心区别 您提到的代码: prompt_embedding = initial_embedding.clone().requires_grad_(True) optimizer = torch.optim.Adam([prompt_embedding...

mysql已经安装,但是通过rpm -q 没有找mysql相关的已安装包

文章目录 现象&#xff1a;mysql已经安装&#xff0c;但是通过rpm -q 没有找mysql相关的已安装包遇到 rpm 命令找不到已经安装的 MySQL 包时&#xff0c;可能是因为以下几个原因&#xff1a;1.MySQL 不是通过 RPM 包安装的2.RPM 数据库损坏3.使用了不同的包名或路径4.使用其他包…...

tree 树组件大数据卡顿问题优化

问题背景 项目中有用到树组件用来做文件目录&#xff0c;但是由于这个树组件的节点越来越多&#xff0c;导致页面在滚动这个树组件的时候浏览器就很容易卡死。这种问题基本上都是因为dom节点太多&#xff0c;导致的浏览器卡顿&#xff0c;这里很明显就需要用到虚拟列表的技术&…...

Selenium常用函数介绍

目录 一&#xff0c;元素定位 1.1 cssSeector 1.2 xpath 二&#xff0c;操作测试对象 三&#xff0c;窗口 3.1 案例 3.2 窗口切换 3.3 窗口大小 3.4 屏幕截图 3.5 关闭窗口 四&#xff0c;弹窗 五&#xff0c;等待 六&#xff0c;导航 七&#xff0c;文件上传 …...