当前位置:网站首页>MySQL cases SQL causes 100% CPU utilization
MySQL cases SQL causes 100% CPU utilization
2022-06-24 03:56:00 【Yaochong】
background
Here's the thing , Let me tell you ...
A few days ago, the customer asked me a question SQL, Keywords are blocked for customer privacy , Change to your own test environment statement
WITH tabs AS ( SELECT ROW_NUMBER() OVER(PARTITION by O_ORDERPRIORITY ORDER BY O_TOTALPRICE DESC) as my_rowid, o_orderkey, O_CUSTKEY O_TOTALPRICE from orders where O_ORDERDATE >'1998-01-01' and O_ORDERDATE<'1998-12-30' ) update tabs set O_TOTALPRICE = O_TOTALPRICE+1 where my_rowid>1;
See this bar SQL There is still a problem with the writing , I adapted it according to his meaning , Let's first analyze the logic of the sentence he wants
according to O_ORDERPRIORITY Order attribute grouping , Update the value in each group where the price is not the largest , So nice , According to the meaning , I should write it as follows ,o_orderkey It is the order table primary key
update orders
set O_TOTALPRICE = O_TOTALPRICE + 1
where o_orderkey
in
(select o_orderkey
from (
SELECT ROW_NUMBER() OVER (PARTITION by O_ORDERPRIORITY ORDER BY O_TOTALPRICE DESC) as my_rowid,
o_orderkey
from orders
where O_ORDERDATE > '1998-01-01'
and O_ORDERDATE < '1998-12-30'
) x
where x.my_rowid > 1
);I remind MySQL Medium batch updates should be executed in batches
CPU100%
A few days later, the customer , say CPU 100% 了 , Slow query SQL formal , The association was updated a few days ago ...
So this SQL Why is it so slow ... First say Oracle The solution in , It can be rewritten as merge into guide SQL go hash join, Add appropriate parallelism if possible ,MySQL8.0 I won't support it merge into
merge into orders o using
(select o_orderkey
from (
SELECT ROW_NUMBER() OVER (PARTITION by O_ORDERPRIORITY ORDER BY O_TOTALPRICE DESC) as my_rowid,
o_orderkey
from orders
where O_ORDERDATE > '1998-01-01'
and O_ORDERDATE < '1998-12-30'
) x
where x.my_rowid > 1) x
on (x.o_orderkey = o.o_orderkey)
when matched then update set o.O_TOTALPRICE = o.O_TOTALPRICE+1So let's look at the implementation plan , About format=tree You can refer to https://cloud.tencent.com/developer/article/1876791 This article , But it's a pity that SQL I won't support it ...
explain format=tree update tpch.orders set O_TOTALPRICE = O_TOTALPRICE + 1 where o_orderkey
in
(select o_orderkey
from (
SELECT ROW_NUMBER() OVER (PARTITION by O_ORDERPRIORITY ORDER BY O_TOTALPRICE DESC) as my_rowid,
o_orderkey
from tpch.orders
where O_ORDERDATE > '1998-01-01'
and O_ORDERDATE < '1998-12-30'
) x
where x.my_rowid > 1
);
-- Output results :
<not executable by iterator executor>Let's look at the execution plan of the normal version
The driven table has no index , This SQL stay MySQL There must be no way to implement the results ,
There are hundreds of thousands of rows of data in the table , But because of the matching factor , Relevance affects 20 Billion rows , So this case is over
Conclusion :
MySQL Not suitable for OLAP Data analysis type SQL, Because it is in 8.0 Support analysis functions , Be careful when implementing in production , He doesn't Oracle So efficient , There is also a need to improve learning
that , about MySQL Do you have any good suggestions for association update ?
More articles are welcome to follow my official account , search dbachongzi Or scan QR code
author : Yao Chong Oracle OCM、MySQL OCP、Oceanbase OBCA、PingCAP PCTA authentication , Good at based on Oracle、MySQL Performance Turning And a variety of relational NoSQL database .
边栏推荐
- An accident caused by a MySQL misoperation, and the "high availability" cannot withstand it!
- Yuanqi forest pushes "youkuang", and farmers' mountain springs follow the "roll"?
- [Tencent cloud update] against 11.11! Here comes the 1.1% discount for enterprises!
- Several options of F8 are very useful
- Building RPM packages - spec Basics
- getLocationInWindow源码
- Dialogue with Google technical experts: soundstream is expected to be used for general audio coding in the future
- TCP three handshakes and four waves
- Summary of common problems of real-time audio and video TRTC - quality
- Web penetration test - 5. Brute force cracking vulnerability - (2) SNMP password cracking
猜你喜欢

618大促:手机品牌“神仙打架”,高端市场“谁主沉浮”?

Halcon knowledge: contour operator on region (2)

Koom of memory leak
![[code Capriccio - dynamic planning] t392 Judgement subsequence](/img/59/9da6d70195ce64b70ada8687a07488.png)
[code Capriccio - dynamic planning] t392 Judgement subsequence

一次 MySQL 误操作导致的事故,「高可用」都顶不住了!

在pycharm中pytorch的安装

ModStartCMS 企业内容建站系统(支持 Laravel9)v4.2.0

Modstartcms theme introductory development tutorial

Black hat actual combat SEO: never be found hijacking

An accident caused by a MySQL misoperation, and the "high availability" cannot withstand it!
随机推荐
2021-10-02: word search. Given an M x n two-dimensional character grid boa
Build a small program + management background in 7 days, and this goose factory HR is blessed!
Industrial security experts talk about how to build security protection capability for government big data platform?
Clickhouse synchronous asynchronous executor
[congratulations] rock solid! A new generation of AMD Blackstone architecture instance is launched!
Optimization of digital transformation management of procurement platform in construction industry
Create a telepresence USB drive using the DD command
How should the server be placed?
Technical dry goods - how to use AI technology to accurately identify mining Trojans
web渗透测试----5、暴力破解漏洞--(1)SSH密码破解
Koom of memory leak
Real time monitoring of water conservancy by RTU of telemetry terminal
开源一款监控数据采集器,啥都能监控
Grp: how to add Prometheus monitoring in GRP service?
Idea 1 of SQL injection bypassing the security dog
Do you understand TLS protocol?
左滑从小窗到大窗口DispatchFrameLayout
Brief ideas and simple cases of JVM tuning - how to tune
Tell you about mvcc
Hprof information in koom shark with memory leak