当前位置:网站首页>2022-07-30 mysql8执行慢SQL-Q17分析
2022-07-30 mysql8执行慢SQL-Q17分析
2022-08-02 02:08:00 【帝尊悟世】
摘要:
以mysql8.0.28执行Q17慢SQL,作为分析对比
环境信息:
- 内存: 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
热力图:
边栏推荐
- Hiring a WordPress Developer: 4 Practical Ways
- Software testing Interface automation testing Pytest framework encapsulates requests library Encapsulates unified request and multiple base path processing Interface association encapsulation Test cas
- LeetCode刷题日记: 33、搜索旋转排序数组
- 软件测试功能测试全套常见面试题【开放性思维题】面试总结4-3
- CodeTon Round 2 D. Magical Array
- oracle查询扫描全表和走索引
- typescript29-枚举类型的特点和原理
- Navicat data shows incomplete resolution
- 搜罗汇总的效应
- Force buckle, 752-open turntable lock
猜你喜欢
个人博客系统项目测试
超大规模的产业实用语义分割数据集PSSL与预训练模型开源啦!
Golang分布式应用之定时任务
密码学的基础:X.690和对应的BER CER DER编码
Constructor instance method inheritance of typescript38-class (implement)
LeetCode刷题日记:74. 搜索二维矩阵
A full set of common interview questions for software testing functional testing [open thinking questions] interview summary 4-3
电子制造仓储条码管理系统解决方案
[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)
Rust P2P Network Application Combat-1 P2P Network Core Concepts and Ping Program
随机推荐
Force buckle, 752-open turntable lock
Centos7 install postgresql and enable remote access
Rasa 3.x 学习系列- Rasa - Issues 4873 dispatcher.utter_message 学习笔记
Constructor instance method inheritance of typescript37-class (extends)
Basic use of typescript34-class
力扣、752-打开转盘锁
volatile原理解析
制造企业数字化转型现状分析
PHP 使用 PHPRedis 与 Predis
【LeetCode每日一题】——654.最大二叉树
LeetCode brushing diary: 33. Search and rotate sorted array
【LeetCode Daily Question】——704. Binary Search
力扣(LeetCode)213. 打家劫舍 II(2022.08.01)
typescript35-class的构造函数
哈希冲突和一致性哈希
3 Month Tester Readme: 4 Important Skills That Impacted My Career
【ORB_SLAM2】SetPose、UpdatePoseMatrices
typescript33 - high-level overview of typescript
Fundamentals of Cryptography: X.690 and Corresponding BER CER DER Encodings
超大规模的产业实用语义分割数据集PSSL与预训练模型开源啦!