当前位置:网站首页>2022-07-29 mysql/stonedb慢SQL-Q17-分析
2022-07-29 mysql/stonedb慢SQL-Q17-分析
2022-07-30 20:31:00 【帝尊悟世】
摘要:
对Q17慢SQL进行分析
SQL分析:
SQL:
/stonedb57/install/bin/mysql -D tpch -e "
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分析:
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: lineitem
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 59986052
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 with pushed condition ((`tpch`.`part`.`p_brand` = 'Brand#23') and (`tpch`.`part`.`p_container` = 'MED BOX'))(t0) Pckrows: 16, susp. 16 (0 empty 0 full). Conditions: 2
*************************** 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: 59986052
filtered: 10.00
Extra: Using where
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
| 1 | PRIMARY | lineitem | ALL | 59986052 | 100 | ||||||
| 1 | PRIMARY | part | eq_ref | PRIMARY | PRIMARY | 4 | tpch.lineitem.l_partkey | 1 | 5 | Using where with pushed condition ((`tpch`.`part`.`p_brand` = 'Brand#23') and (`tpch`.`part`.`p_container` = 'MED BOX'))(t0) Pckrows: 16, susp. 16 (0 empty 0 full). Conditions: 2 | |
| 2 | DEPENDENT SUBQUERY | lineitem | ALL | 59986052 | 10 | Using where |
热力图:

拆分SQL后分析:
外层表查询:
time /stonedb57/install/bin/mysql -D tpch -e "
select
l_extendedprice
from
lineitem,
part
where
p_partkey = l_partkey\G
"*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: lineitem
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 59986052
filtered: 100.00
Extra: NULL
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: part
partitions: NULL
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: tpch.lineitem.l_partkey
rows: 1
filtered: 100.00
Extra: NULL
内层查询:
time /stonedb57/install/bin/mysql -D tpch -e "
explain select
0.2 * avg(l_quantity)
from
lineitem \G
"*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: lineitem
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 59986052
filtered: 100.00
Extra: NULL
边栏推荐
猜你喜欢
随机推荐
[PM only] Quickly count who else in the team has not registered and reported information, and quickly screen out the members of their own project team who have not completed the list of XXX work items
啊?现在初级测试招聘都要求会自动化了?
MySQL 高级(进阶) SQL 语句 (一)
MySQL的on duplicate key update 的使用
MySQL 多表关联一对多查询实现取最新一条数据
Ordinary int main(){} does not write return 0; what will happen?
HJ85 最长回文子串
【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码
软考 --- 数据库(6)数据仓库、分布式数据库
基于人脸的常见表情识别(2)——数据获取与整理
Common Expression Recognition Based on Face (1) - Basic Knowledge of Deep Learning
Multi-threaded mutex application RAII mechanism
5分钟搞懂MySQL - 行转列
Recommender systems: overview of the characteristics of architecture: user/item engineering -- -- -- -- -- -- -- -- > recall layer > sort layer - > test/evaluation 】 【 cold start problems, real-time 】
银行数据资产转换能力弱?思迈特软件助力解决银行困境
PR视频剪辑软件教程
Mysql8创建用户以及赋权操作
明解C语言第六章习题
mysqldump导出提示:mysqldump [Warning] Using a password on the command line interface can be insecure
Can't find the distributed lock of Redisson?









