当前位置:网站首页>2022-07-30 mysql8 executes slow SQL-Q17 analysis
2022-07-30 mysql8 executes slow SQL-Q17 analysis
2022-08-02 02:08:00 【Emperor Zun Wu Shi】
摘要:
以mysql8.0.28执行Q17慢SQL,as an analytical comparison
环境信息:
- 内存: 8GB
- cpu: 8核心,3.2GHz
- mysql: 8.0.28
执行分析:
DDL:
mysql> show create table lineitem\G
*************************** 1. row ***************************
Table: lineitem
Create Table: CREATE TABLE `lineitem` (
`l_orderkey` int NOT NULL,
`l_partkey` int NOT NULL,
`l_suppkey` int NOT NULL,
`l_linenumber` int NOT NULL,
`l_quantity` decimal(15,2) NOT NULL,
`l_extendedprice` decimal(15,2) NOT NULL,
`l_discount` decimal(15,2) NOT NULL,
`l_tax` decimal(15,2) NOT NULL,
`l_returnflag` char(1) NOT NULL,
`l_linestatus` char(1) NOT NULL,
`l_shipdate` date NOT NULL,
`l_commitdate` date NOT NULL,
`l_receiptdate` date NOT NULL,
`l_shipinstruct` char(25) NOT NULL,
`l_shipmode` char(10) NOT NULL,
`l_comment` varchar(44) NOT NULL,
PRIMARY KEY (`l_orderkey`,`l_linenumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)
mysql> show create table part\G
*************************** 1. row ***************************
Table: part
Create Table: CREATE TABLE `part` (
`p_partkey` int NOT NULL,
`p_name` varchar(55) NOT NULL,
`p_mfgr` char(25) NOT NULL,
`p_brand` char(10) NOT NULL,
`p_type` varchar(25) NOT NULL,
`p_size` int NOT NULL,
`p_container` char(10) NOT NULL,
`p_retailprice` decimal(15,2) NOT NULL,
`p_comment` varchar(23) NOT NULL,
PRIMARY KEY (`p_partkey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.02 sec)
SQL:
select
sum(l_extendedprice) / 7.0 as avg_yearly
from
lineitem,
part
where
p_partkey = l_partkey
and p_brand = 'Brand#23'
and p_container = 'MED BOX'
and l_quantity < (
select
0.2 * avg(l_quantity)
from
lineitem
where
l_partkey = p_partkey
);explain分析:
mysql> explain select
from
lineitem
where
l_partkey = p_partkey
)\G -> sum(l_extendedprice) / 7.0 as avg_yearly
-> from
-> lineitem,
-> part
-> where
-> p_partkey = l_partkey
-> and p_brand = 'Brand#23'
-> and p_container = 'MED BOX'
-> and l_quantity < (
-> select
-> 0.2 * avg(l_quantity)
-> from
-> lineitem
-> where
-> l_partkey = p_partkey
-> )\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: lineitem
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 31751480
filtered: 100.00
Extra: NULL
*************************** 2. row ***************************
id: 1
select_type: PRIMARY
table: part
partitions: NULL
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: tpch.lineitem.l_partkey
rows: 1
filtered: 5.00
Extra: Using where
*************************** 3. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: lineitem
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 31751480
filtered: 10.00
Extra: Using where
3 rows in set, 2 warnings (0.01 sec)
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | |
| 1 | PRIMARY | lineitem | ALL | 31751480 | 100 | |||||||
| 1 | PRIMARY | part | eq_ref | PRIMARY | PRIMARY | 4 | tpch.lineitem.l_partkey | 1 | 5 | Using where | ||
| 2 | DEPENDENT SUBQUERY | lineitem | ALL | 31751480 | 10 | Using where |
耗时分析:
性能分析:
iotop:

top:
[[email protected] ~]# ps -ef | grep mysqld
mysql 19895 1 39 20:21 ? 00:18:16 /usr/libexec/mysqld --basedir=/usr
root 20055 1793 0 21:07 pts/1 00:00:00 grep --color=auto mysqld
[[email protected] ~]#
[[email protected] ~]# top -Hp 19895

热力图:

边栏推荐
- typescript34-class的基本使用
- leetcode/字符串中的变位词-s1字符串的某个排列是s2的子串
- Understand the big model in seconds | 3 steps to get AI to write a summary
- LeetCode Review Diary: 34. Find the first and last position of an element in a sorted array
- LeetCode Review Diary: 153. Find the Minimum Value in a Rotated Sort Array
- volatile原理解析
- LeetCode刷题日记:74. 搜索二维矩阵
- Fly propeller power space future PIE - Engine Engine build earth science
- Centos7 安装postgresql并开启远程访问
- AOF重写
猜你喜欢

十字光标太小怎么调节、CAD梦想画图算量技巧

Chengdu openGauss user group recruit!

飞桨开源社区季度报告来啦,你想知道的都在这里

秒懂大模型 | 3步搞定AI写摘要

云和恩墨:让商业数据库时代的价值在openGauss生态上持续繁荣
A full set of common interview questions for software testing functional testing [open thinking questions] interview summary 4-3

Win Go开发包安装配置、GoLand配置

Typescript31 - any type

飞桨助力航天宏图PIE-Engine地球科学引擎构建

Scheduled tasks for distributed applications in Golang
随机推荐
AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
typescript37-class的构造函数实例方法继承(extends)
Win Go开发包安装配置、GoLand配置
Check if IP or port is blocked
typeof in typescript32-ts
3.Bean的作用域与生命周期
检查IP或端口是否被封
LeetCode brushing diary: 53, the largest sub-array and
求大神解答,这种 sql 应该怎么写?
飞桨开源社区季度报告来啦,你想知道的都在这里
bool框架::PosInGrid (const简历:关键点kp, int &posX, int诗句)
密码学的基础:X.690和对应的BER CER DER编码
Simple example of libcurl accessing url saved as file
云和恩墨:让商业数据库时代的价值在openGauss生态上持续繁荣
Handwriting a blogging platform ~ Day 3
超大规模的产业实用语义分割数据集PSSL与预训练模型开源啦!
CodeTon Round 2 D. Magical Array
AntPathMatcher使用
typescript30-any类型
Use baidu EasyDL implement factory workers smoking behavior recognition