MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点1:sys.statement_analysis视图

news2024/10/6 1:43:24

文章目录

    • MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点1:sys.statement_analysis视图
      • 视图sys.statement_analysis各列定义
      • 视图sys.statement_analysis视图的定义
      • 视图sys.statement_analysis各列解释
      • 例题
      • 例题解析
      • 参考

MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点1:sys.statement_analysis视图

通过系统性能视图sys.statement_analysis可以查看规范化后SQL语句的汇总统计信息。相当于MySQL Enterprise Monitor的“查询分析”视图。默认情况下,输出结果按总等待时间(max_latency)降序排序。

视图sys.statement_analysis各列定义

视图sys.statement_analysis的各列定义如下:

mysql> desc sys.statement_analysis;
+-----------------------+-----------------+------+-----+---------+-------+
| Field                 | Type            | Null | Key | Default | Extra |
+-----------------------+-----------------+------+-----+---------+-------+
| query                 | longtext        | YES  |     | NULL    |       |
| db                    | varchar(64)     | YES  |     | NULL    |       |
| full_scan             | varchar(1)      | NO   |     |         |       |
| exec_count            | bigint unsigned | NO   |     | NULL    |       |
| err_count             | bigint unsigned | NO   |     | NULL    |       |
| warn_count            | bigint unsigned | NO   |     | NULL    |       |
| total_latency         | varchar(11)     | YES  |     | NULL    |       |
| max_latency           | varchar(11)     | YES  |     | NULL    |       |
| avg_latency           | varchar(11)     | YES  |     | NULL    |       |
| lock_latency          | varchar(11)     | YES  |     | NULL    |       |
| cpu_latency           | varchar(11)     | YES  |     | NULL    |       |
| rows_sent             | bigint unsigned | NO   |     | NULL    |       |
| rows_sent_avg         | decimal(21,0)   | NO   |     | 0       |       |
| rows_examined         | bigint unsigned | NO   |     | NULL    |       |
| rows_examined_avg     | decimal(21,0)   | NO   |     | 0       |       |
| rows_affected         | bigint unsigned | NO   |     | NULL    |       |
| rows_affected_avg     | decimal(21,0)   | NO   |     | 0       |       |
| tmp_tables            | bigint unsigned | NO   |     | NULL    |       |
| tmp_disk_tables       | bigint unsigned | NO   |     | NULL    |       |
| rows_sorted           | bigint unsigned | NO   |     | NULL    |       |
| sort_merge_passes     | bigint unsigned | NO   |     | NULL    |       |
| max_controlled_memory | varchar(11)     | YES  |     | NULL    |       |
| max_total_memory      | varchar(11)     | YES  |     | NULL    |       |
| digest                | varchar(64)     | YES  |     | NULL    |       |
| first_seen            | timestamp(6)    | NO   |     | NULL    |       |
| last_seen             | timestamp(6)    | NO   |     | NULL    |       |
+-----------------------+-----------------+------+-----+---------+-------+
26 rows in set (0.00 sec)

视图sys.statement_analysis视图的定义

根据视图sys.statement_analysis的定义,可以看到数据主要是通过performance_schema.events_statements_summary_by_digest表取得的。

视图的定义如下:

mysql> show create view statement_analysis\G
*************************** 1. row ***************************
                View: statement_analysis
         Create View: 
CREATE ALGORITHM=MERGE DEFINER=`mysql.sys`@`localhost` SQL SECURITY INVOKER VIEW `statement_analysis` (
    `query`,
    `db`,
    `full_scan`,
    `exec_count`,
    `err_count`,
    `warn_count`,
    `total_latency`,
    `max_latency`,
    `avg_latency`,
    `lock_latency`,
    `cpu_latency`,
    `rows_sent`,
    `rows_sent_avg`,
    `rows_examined`,
    `rows_examined_avg`,
    `rows_affected`,
    `rows_affected_avg`,
    `tmp_tables`,
    `tmp_disk_tables`,
    `rows_sorted`,
    `sort_merge_passes`,
    `max_controlled_memory`,
    `max_total_memory`,
    `digest`,
    `first_seen`,
    `last_seen`
)
    AS
        SELECT
            `sys`.`format_statement`(`performance_schema`.`events_statements_summary_by_digest`.`digest_text`)                                                                                              AS
            `query`,
            `performance_schema`.`events_statements_summary_by_digest`.`schema_name`                                                                                                                        AS
            `db`,
            if(((`performance_schema`.`events_statements_summary_by_digest`.`sum_no_good_index_used` > 0) OR(`performance_schema`.`events_statements_summary_by_digest`.
            `sum_no_index_used` > 0)), '*', '') AS `full_scan`,
            `performance_schema`.`events_statements_summary_by_digest`.`count_star`                                                                                                                         AS
            `exec_count`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_errors`                                                                                                                         AS
            `err_count`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_warnings`                                                                                                                       AS
            `warn_count`,
            format_pico_time(`performance_schema`.`events_statements_summary_by_digest`.`sum_timer_wait`)                                                                                                   AS
            `total_latency`,
            format_pico_time(`performance_schema`.`events_statements_summary_by_digest`.`max_timer_wait`)                                                                                                   AS
            `max_latency`,
            format_pico_time(`performance_schema`.`events_statements_summary_by_digest`.`avg_timer_wait`)                                                                                                   AS
            `avg_latency`,
            format_pico_time(`performance_schema`.`events_statements_summary_by_digest`.`sum_lock_time`)                                                                                                    AS
            `lock_latency`,
            format_pico_time(`performance_schema`.`events_statements_summary_by_digest`.`sum_cpu_time`)                                                                                                     AS
            `cpu_latency`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_rows_sent`                                                                                                                      AS
            `rows_sent`,
            round(ifnull((`performance_schema`.`events_statements_summary_by_digest`.`sum_rows_sent` / nullif(`performance_schema`.`events_statements_summary_by_digest`.
            `count_star`, 0)), 0), 0)          AS `rows_sent_avg`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_rows_examined`                                                                                                                  AS
            `rows_examined`,
            round(ifnull((`performance_schema`.`events_statements_summary_by_digest`.`sum_rows_examined` / nullif(`performance_schema`.
            `events_statements_summary_by_digest`.`count_star`, 0)), 0), 0)      AS `rows_examined_avg`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_rows_affected`                                                                                                                  AS
            `rows_affected`,
            round(ifnull((`performance_schema`.`events_statements_summary_by_digest`.`sum_rows_affected` / nullif(`performance_schema`.
            `events_statements_summary_by_digest`.`count_star`, 0)), 0), 0)      AS `rows_affected_avg`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_created_tmp_tables`                                                                                                             AS
            `tmp_tables`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_created_tmp_disk_tables`                                                                                                        AS
            `tmp_disk_tables`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_sort_rows`                                                                                                                      AS
            `rows_sorted`,
            `performance_schema`.`events_statements_summary_by_digest`.`sum_sort_merge_passes`                                                                                                              AS
            `sort_merge_passes`,
            format_bytes(`performance_schema`.`events_statements_summary_by_digest`.`max_controlled_memory`)                                                                                                AS
            `max_controlled_memory`,
            format_bytes(`performance_schema`.`events_statements_summary_by_digest`.`max_total_memory`)                                                                                                     AS
            `max_total_memory`,
            `performance_schema`.`events_statements_summary_by_digest`.`digest`                                                                                                                             AS
            `digest`,
            `performance_schema`.`events_statements_summary_by_digest`.`first_seen`                                                                                                                         AS
            `first_seen`,
            `performance_schema`.`events_statements_summary_by_digest`.`last_seen`                                                                                                                          AS
            `last_seen`
        FROM
            `performance_schema`.`events_statements_summary_by_digest`
        ORDER BY
            `performance_schema`.`events_statements_summary_by_digest`.`sum_timer_wait` DESC
character_set_client: utf8mb4
collation_connection: utf8mb4_0900_ai_ci
1 row in set (0.00 sec)

视图sys.statement_analysis各列解释

各列的含义如下:

列名英文解释中文解释
queryThe normalized statement string规范化的语句字符串
dbThe default database for the statement, or NULL if there is none语句的默认数据库,如果没有,则为NULL
full_scanThe total number of full table scans performed by occurrences of the statement执行的全表扫描的总数
exec_countThe total number of times the statement has executed语句执行的总次数
err_countThe total number of errors produced by occurrences of the statement语句执行所产生的错误总数。
warn_countThe total number of warnings produced by occurrences of the statement语句执行所产生的警告总数。
total_latencyThe total wait time of timed occurrences of the statement语句执行总等待时间。
max_latencyThe maximum single wait time of timed occurrences of the statement语句执行最大单次等待时间。
avg_latencyThe average wait time per timed occurrence of the statement语句执行平均等待时间。
lock_latencyThe total time waiting for locks by timed occurrences of the statement语句执行总锁等待时间。
cpu_latencyThe time spent on CPU for the current thread当前线程在cpu上花费的时间
rows_sentThe total number of rows returned by occurrences of the statement语句执行所返回的总行数
rows_sent_avgThe average number of rows returned per occurrence of the statement语句单次执行平均返回的行数
rows_examinedThe total number of rows read from storage engines by occurrences of the statement语句执行从存储引擎读取的总行数
rows_examined_avgThe average number of rows read from storage engines per occurrence of the statement语句单次执行从存储引擎读取的平均行数
rows_affectedThe total number of rows affected by occurrences of the statement语句执行影响的总行数
rows_affected_avgThe average number of rows affected per occurrence of the statement语句单次执行影响的平均行数
tmp_tablesThe total number of internal in-memory temporary tables created by occurrences of the statement语句执行创建的内存中内部临时表的总数
tmp_disk_tablesThe total number of internal on-disk temporary tables created by occurrences of the statement语句执行创建的磁盘上内部临时表的总数
rows_sortedThe total number of rows sorted by occurrences of the statement语句执行排序的总行数
sort_merge_passesThe total number of sort merge passes by occurrences of the statement语句执行排序合并传递总数.
max_controlled_memoryThe maximum amount of controlled memory (bytes) used by the statement 。This column was added in MySQL 8.0.31语句使用的最大受控内存量(字节),在MySQL 8.0.31中添加
max_total_memoryThe maximum amount of memory (bytes) used by the statement。This column was added in MySQL 8.0.31语句使用的最大内存量(字节),在MySQL 8.0.31中添加
digestThe statement digest语句摘要
first_seenThe time at which the statement was first seen语句的最初时间
last_seenThe time at which the statement was most recently seen语句的最近时间

例题

Choose two.
Examine this statement and output:

mysql> SELECT ROW_NUMBER() OVER() AS QN,
query, exec_count, avg_latency, lock_latency
FROM sys.statement_analysis
ORDER BY exec_count;

在这里插入图片描述

You must try to reduce query execution time.
Which two queries should you focus on?

A) QN=2
B) QN=3
C) QN=4
D) QN=1
E) QN=5

例题解析

根据题目我们要减少查询的执行时间。
实践中在调优的过程中,我们通常找的是总执行时间最长或者单次执行时间最长的SQL。
对于题目而言,我们要关注总等待时间,查询的总等待时间为exec_count * avg_latency ,lock等待时间为 lock_latency。

1 秒(s)=1000 毫秒(ms)
1 毫秒(ms)=1000 微秒(us)

各查询总等待时间:

QN=1  381268 * 31.44          =11987065.92 ms
QN=2  150317 * 358.34        =53864593.78 us = 53864.59378 ms
QN=3  600 * 523.32             = 313992 ms
QN=4  200 * 10.32 = 2064 s  = 2064000 ms
QN=5  1* 21.03  = 21.03 s    = 21030 ms 

所以,我们可以看到总等待时间最长是QN=1和QN=4 。

参考答案: CD

参考

https://dev.mysql.com/doc/refman/8.0/en/sys-statement-analysis.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/424812.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

5G边缘计算网关用于智能消防安全

随着人们对智能消防安全的需求不断增长,5G边缘计算网关作为一种新型技术,已经被广泛应用于消防设备的智能监控和管理中。本文将介绍5G边缘计算网关在智能消防安全中的应用,并给出一个Python代码示例。 一、5G边缘计算网关在智能消防安全中的应…

OKR系统改变您的团队

使用Zoho Projects易于使用的OKR系统将雄心转化为行动。简化您计划、跟踪和报告团队目标的方式。 一、使用这个强大的OKR工具提升结果 1、自动组织团队的目标 在公司、部门、团队和个人层面创建和跟踪OKR,以实现真正的整体OKR管理。 2、实时跟踪进度 使团队能够使…

阻塞队列 BlockingQueue

阻塞队列(BlockingQueue)是一个支持两个附加操作的队列。这两个附加的操作支持阻塞的插入和移除的方法: 支持阻塞的插入方法:当队列满时,队列会阻塞插入元素的线程,直到队列不满;支持阻塞的移除…

HTML5 <header> 标签、HTML5 <html> 标签

HTML5 <header> 标签 实例 HTML5 &#xff0c;<header>标签用来表示介绍性的内容&#xff0c;即&#xff0c;定义了文档中的页眉&#xff0c;请参考下述示例&#xff1a; <article> 的页眉&#xff1a; <article><header><h1>Internet …

SpringSecurity之入门案例

前言 前面一篇文章讲了一些关于SpringSecurity的基本内容、两大核心模块以及学习他所需要的基本技能点。接下来&#xff0c;带大家进入到一个基本的入门案例&#xff01;&#xff01;&#xff01; 操作步骤 1、创建Springboot工程 首先通过idea开发工具&#xff0c;创建一个…

代码随想录_二叉树_leetcode669 108 538

leetcode 669. 修剪二叉搜索树 669. 修剪二叉搜索树 给你二叉搜索树的根节点 root &#xff0c;同时给定最小边界low 和最大边界 high。通过修剪二叉搜索树&#xff0c;使得所有节点的值在[low, high]中。修剪树 不应该 改变保留在树中的元素的相对结构 (即&#xff0c;如果没…

翻译国外文章-整篇文章的翻译

chatgpt翻译是专业的吗 ChatGPT是一种AI语言模型&#xff0c;它可以用来执行各种自然语言处理任务&#xff0c;包括翻译。然而&#xff0c;ChatGPT的翻译结果并不是专业的翻译&#xff0c;因为该模型并不是专为翻译任务训练的。 虽然ChatGPT的翻译质量相对较高&#xff0c;但…

你了解C语言中的数组指针和函数指针吗?

如题&#xff0c;本篇文章重点讲解C语言中的数组指针和函数指针。这2种指针其实都不是很常用&#xff0c;个人感觉使用起来代码的可读性不是很高&#xff0c;但是还是需要了解一下。 数组指针 数组指针&#xff0c;即指向数组的指针&#xff0c;是用来存放数组的地址的。那如…

JavaScript对象类型之Array及Object

目录 一、Array &#xff08;1&#xff09;语法 &#xff08;2&#xff09;API 二、Object &#xff08;1&#xff09;语法 &#xff08;2&#xff09;特色&#xff1a;属性增删 &#xff08;3&#xff09;特色&#xff1a;this &#xff08;4&#xff09;特色&#xf…

公司测试员用例写得乱七八糟,测试总监制定了这份《测试用例编写规范》

统一测试用例编写的规范&#xff0c;为测试设计人员提供测试用例编写的指导&#xff0c;提高编写的测试用例的可读性&#xff0c;可执行性、合理性。为测试执行人员更好执行测试&#xff0c;提高测试效率&#xff0c;最终提高公司整个产品的质量。 一、范围 适用于集成测试用…

SAP MDG —— 使用DIF导入物料主数据 Part3 进阶篇

文章目录关于使用DIF处理物料主数据的相关信息IDOC 缩减IDOC 扩展物料编码的主键映射 Key Mapping主键映射和内部给号其他主键的主键映射值映射 Value Mapping将物料主数据导出为IDoc文件 - MATMAS / CLFMAS错误处理本章小结关于使用DIF处理物料主数据的相关信息 IDOC 缩减 场…

机器学习:基于KNN对葡萄酒质量进行分类

机器学习&#xff1a;基于KNN对葡萄酒质量进行分类 作者&#xff1a;i阿极 作者简介&#xff1a;Python领域新星作者、多项比赛获奖者&#xff1a;博主个人首页 &#x1f60a;&#x1f60a;&#x1f60a;如果觉得文章不错或能帮助到你学习&#xff0c;可以点赞&#x1f44d;收藏…

网盘工具助力律师团队文件管理

律师的日常工作离不开文件管理。文档管理对于律师而言是一门必修课&#xff0c;这也是日积月累的工作。良好的文件管理习惯可以帮助我们让工作流程化、标准化&#xff0c;助力知识管理&#xff0c;避免职业风险&#xff0c;提升团队工作效率。 好用的文件管理工具也可以帮助律师…

Python 实验三 控制语句

1.从键盘接收整数的一百分制成绩&#xff08;0到100)&#xff0c;要求输出其对应的成绩等级A-E。其中&#xff0c;90分&#xff08;包含&#xff09;以上为A&#xff0c;80-89&#xff08;均包含&#xff09;分为B&#xff0c;70-79(均包含&#xff09;分为C&#xff0c;60-69&…

[网络安全] Windows Server 设置文件屏蔽防止黑客利用漏洞上传特定类型的非法文件

我在负责网站运维期间&#xff0c;遇到过一次黑客利用网站内使用的开源文件上传工具漏洞上传非法文件&#xff08;可执行脚本&#xff09; 我是通过设置文件屏蔽来防止此类事件的再次发生。特在此做下记录。 文章目录前言一、黑客是怎么攻击我的二、我是怎么防范的2.1 Windows …

我学习网络安全的心得

我的学习心得&#xff0c;我认为能不能自学成功的要素有两点。 第一点就是自身的问题&#xff0c;虽然想要转行学习安全的人很多&#xff0c;但是非常强烈的想要转行学好的人是小部分。而大部分人只是抱着试试的心态来学习安全&#xff0c;这是完全不可能的。 所以能不能学成并…

Matplotlib 二维图像绘制方法

Matplotlib 二维图像绘制方法 介绍 Matplotlib 是支持 Python 语言的开源绘图库,因为其支持丰富的绘图类型、简单的绘图方式以及完善的接口文档,深受 Python 工程师、科研学者、数据工程师等各类人士的喜欢。本次实验课程中,我们将学会使用 Matplotlib 绘图的方法和技巧。…

GitHub的简介与Idea集成Git

六大基础功能 &#xff1a; 创建远程库、代码推送&#xff08;Push&#xff09;、代码拉取&#xff08;Pull&#xff09;、代码克隆&#xff08;Clone&#xff09;、SSH免密登录、Idea集成GitHub GitHub 网址&#xff1a;https://github.com/ 1.创建远程仓库 登录后的页面右上…

亚马逊云科技帮助BMW Financial Services设计和构建数据架构

BMW Group和亚马逊云科技于2020年宣布达成全面战略合作。在re:Invent2019上&#xff0c;BMW和亚马逊云科技展示了新的云数据中心平台&#xff0c;先是大致介绍了不同的数据平台原型&#xff0c;然后介绍了构建BMW Group云数据中心的过程。Amazon Data Lab使用亚马逊云科技的云数…

Volatile关键字的作用探究

前言 今天下午BOSS上投了个简历小试了一波水&#xff0c;结果被问到一个知识点volatile关键字的作用&#xff0c;我回答了线程的可见性&#xff0c;另一个死活想不起来是什么&#xff0c;当回到工位上看了眼笔记&#xff0c;才想起来。这种知识点其实平时使用的频率还是挺高的…