当前位置:网站首页>2022-08-01 mysql/stoonedb慢SQL-Q18分析
2022-08-01 mysql/stoonedb慢SQL-Q18分析
2022-08-02 02:08:00 【帝尊悟世】
摘要:
分析慢SQL-Q18出现的原因
DDL分析:
SQL:
select
c_name,
c_custkey,
o_orderkey,
o_orderdate,
o_totalprice,
sum(l_quantity)
from
customer,
orders,
lineitem
where
o_orderkey in (
select
l_orderkey
from
lineitem
group by
l_orderkey
having
sum(l_quantity) > 300 )
and c_custkey = o_custkey
and o_orderkey = l_orderkey
group by
c_name,
c_custkey,
o_orderkey,
o_orderdate,
o_totalprice
order by
o_totalprice desc,
o_orderdate
limit 100;innodb的explain分析:
mysql> explain select
-> c_name,
-> c_custkey,
-> o_orderkey,
-> o_orderdate,
-> o_totalprice,
-> sum(l_quantity)
-> from
-> customer,
-> orders,
-> lineitem
-> where
-> o_orderkey in (
-> select
->
Display all 1017 possibilities? (y or n)
-> l_orderkey
-> from
->
Display all 1017 possibilities? (y or n)
-> lineitem
-> group by
->
Display all 1017 possibilities? (y or n)
-> l_orderkey
-> having
->
Display all 1017 possibilities? (y or n)
-> sum(l_quantity) > 300 )
-> and c_custkey = o_custkey
-> and o_orderkey = l_orderkey
-> group by
-> c_name,
-> c_custkey,
-> o_orderkey,
-> o_orderdate,
-> o_totalprice
-> order by
-> o_totalprice desc,
-> o_orderdate
-> limit 100\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: orders
partitions: NULL
type: ALL
possible_keys: PRIMARY
key: NULL
key_len: NULL
ref: NULL
rows: 13754753
filtered: 100.00
Extra: Using where; Using temporary; Using filesort
*************************** 2. row ***************************
id: 1
select_type: PRIMARY
table: customer
partitions: NULL
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: tpch.orders.o_custkey
rows: 1
filtered: 100.00
Extra: NULL
*************************** 3. row ***************************
id: 1
select_type: PRIMARY
table: lineitem
partitions: NULL
type: ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: tpch.orders.o_orderkey
rows: 4
filtered: 100.00
Extra: NULL
*************************** 4. row ***************************
id: 2
select_type: SUBQUERY
table: lineitem
partitions: NULL
type: index
possible_keys: PRIMARY
key: PRIMARY
key_len: 8
ref: NULL
rows: 31751480
filtered: 100.00
Extra: NULL
4 rows in set, 1 warning (0.01 sec)
| select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | |
| PRIMARY | orders | ALL | PRIMARY | 13754753 | 100 | Using where; Using temporary; Using filesort | |||||
| PRIMARY | customer | eq_ref | PRIMARY | PRIMARY | 4 | tpch.orders.o_custkey | 1 | 100 | |||
| PRIMARY | lineitem | ref | PRIMARY | PRIMARY | 4 | tpch.orders.o_orderkey | 4 | 100 | |||
| SUBQUERY | lineitem | index | PRIMARY | PRIMARY | 8 | 31751480 | 100 |
stonedb的explain分析:
mysql> explain select
-> c_name,
-> c_custkey,
-> o_orderkey,
-> o_orderdate,
-> o_totalprice,
-> sum(l_quantity)
-> from
-> customer,
-> orders,
-> lineitem
-> where
-> o_orderkey in (
-> select
-> l_orderkey
-> from
-> lineitem
-> group by
-> l_orderkey
-> having
-> sum(l_quantity) > 300 )
-> and c_custkey = o_custkey
-> and o_orderkey = l_orderkey
-> group by
-> c_name,
-> c_custkey,
-> o_orderkey,
-> o_orderdate,
-> o_totalprice
-> order by
-> o_totalprice desc,
-> o_orderdate
-> limit 100\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: lineitem
partitions: NULL
type: ALL
possible_keys: PRIMARY
key: NULL
key_len: NULL
ref: NULL
rows: 59986052
filtered: 100.00
Extra: Using where with pushed condition <in_optimizer>(`tpch`.`lineitem`.`l_orderkey`,`tpch`.`lineitem`.`l_orderkey` in ( <materialize> (/* select#2 */ select `tpch`.`lineitem`.`l_orderkey` from `tpch`.`lineitem` group by `tpch`.`lineitem`.`l_orderkey` having (sum(`tpch`.`lineitem`.`l_quantity`) > 300) ), <primary_index_lookup>(`tpch`.`lineitem`.`l_orderkey` in <temporary table> on <auto_key> where ((`tpch`.`lineitem`.`l_orderkey` = `materialized-subquery`.`l_orderkey`)))))(t0) Pckrows: 916, susp. 916 (0 empty 0 full). Conditions: 1; Using temporary; Using filesort
*************************** 2. row ***************************
id: 1
select_type: PRIMARY
table: orders
partitions: NULL
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: tpch.lineitem.l_orderkey
rows: 1
filtered: 100.00
Extra: NULL
*************************** 3. row ***************************
id: 1
select_type: PRIMARY
table: customer
partitions: NULL
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: tpch.orders.o_custkey
rows: 1
filtered: 100.00
Extra: NULL
*************************** 4. row ***************************
id: 2
select_type: SUBQUERY
table: lineitem
partitions: NULL
type: ALL
possible_keys: PRIMARY
key: NULL
key_len: NULL
ref: NULL
rows: 59986052
filtered: 100.00
Extra: Using temporary; Using filesort
4 rows in set, 1 warning (54.11 sec)
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | |||
| 1 | PRIMARY | lineitem | ALL | PRIMARY | 59986052 | 100 | Using where with pushed condition <in_optimizer>(`tpch`.`lineitem`.`l_orderkey`,`tpch`.`lineitem`.`l_orderkey` in ( <materialize> (/* select#2 */ select `tpch`.`lineitem`.`l_orderkey` from `tpch`.`lineitem` group by `tpch`.`lineitem`.`l_orderkey` having (sum(`tpch`.`lineitem`.`l_quantity`) > 300) ), <primary_index_lookup>(`tpch`.`lineitem`.`l_orderkey` in <temporary table> on <auto_key> where ((`tpch`.`lineitem`.`l_orderkey` = `materialized-subquery`.`l_orderkey`)))))(t0) Pckrows: 916, susp. 916 (0 empty 0 full). Conditions: 1; Using temporary; Using filesort | |||||||
| 1 | PRIMARY | orders | eq_ref | PRIMARY | PRIMARY | 4 | tpch.lineitem.l_orderkey | 1 | 100 | |||||
| 1 | PRIMARY | customer | eq_ref | PRIMARY | PRIMARY | 4 | tpch.orders.o_custkey | 1 | 100 | |||||
| 2 | SUBQUERY | lineitem | ALL | PRIMARY | 59986052 | 100 | Using temporary; Using filesort |
执行分析:
热力图:


hash join数据统计:
[2022-08-01 19:27:48.120105] [1369856] End traversed 8380864/8380864 rows.
[2022-08-01 19:28:28.177049] [1369856] Begin match dim of 32986052 rows, spliting into 64 threads with packs type.
[2022-08-01 19:29:07.932297] [1369856] End match dim. Produced tuples:32986052/32986052
[2022-08-01 19:29:07.985311] [1369856] Tuples after inner join 1-2 [hash]: 32986052 [111]
[2022-08-01 19:29:08.286386] [1369856] GroupTable begin, initialized for up to 32986052 groups, 53+31 bytes (3171 MB)
[2022-08-01 19:29:08.529321] [1369856] Aggregating: 32986052 tuples left.
[2022-08-01 19:30:40.828429] [1369856] Group/Aggregate end. Begin generating output.
[2022-08-01 19:30:40.828502] [1369856] Output rows: 8249593, output table row limit: 8249593
[2022-08-01 19:31:06.163156] [1369856] Generating output end. Aggregated (8249593 group). Omitted packrows: 0 + 0 partially, out of 26622 total.
[2022-08-01 19:31:08.930503] [1369856] Heap Sort begin, initialized for 8249593 rows, 16+0+3 bytes each.
[2022-08-01 19:32:21.876613] [1369856] Sorted end, rows retrieved.
边栏推荐
猜你喜欢

【LeetCode每日一题】——103.二叉树的锯齿形层序遍历

Personal blog system project test

nacos启动报错,已配置数据库,单机启动

Speed up your programs with bitwise operations

手写一个博客平台~第三天

HSDC is related to Independent Spanning Tree

3 Month Tester Readme: 4 Important Skills That Impacted My Career

Constructor of typescript35-class

『网易实习』周记(二)

After graduating from three books, I was rejected by Tencent 14 times, and finally successfully joined Alibaba
随机推荐
力扣 1374. 生成每种字符都是奇数个的字符串
Force buckle, 752-open turntable lock
PHP 使用 PHPRedis 与 Predis
垃圾回收器CMS和G1
Huawei's 5-year female test engineer resigns: what a painful realization...
成都openGauss用户组招募啦!
秒懂大模型 | 3步搞定AI写摘要
LeetCode刷题日记: 33、搜索旋转排序数组
typescript35-class的构造函数
3. Bean scope and life cycle
Speed up your programs with bitwise operations
Rasa 3.x 学习系列- Rasa - Issues 4873 dispatcher.utter_message 学习笔记
Project Background Technology Express
乱七八糟的网站
LeetCode brush diary: LCP 03. Machine's adventure
3.Bean的作用域与生命周期
Win Go开发包安装配置、GoLand配置
[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)
messy website
When paying attention to the "Internet +" model, you usually only focus on the "Internet +" model itself