当前位置:网站首页>We found a huge hole in MySQL: do not judge the number of rows affected by update!!!
We found a huge hole in MySQL: do not judge the number of rows affected by update!!!
2022-07-01 06:59:00 【Java technology stack】
Click on the official account ,Java dried food Timely delivery 
source :cnblogs.com/yjmyzz/p/13562182.html
In the business system , Use update Statement updating data is a normal scenario , We often pass through update Number of rows updated , To make some business judgments , Similar to the following pseudo code :(mybatis + mysql scene )
if (xxxMapper.updateByPrimaryKeySelective(entity)>0){
// The update is successful , Do other business processing
}But there's a hole ,mysql in update Number of rows affected >0 It's conditional , If there is a table :

There's only one record in it (ID=1), We use it update Update one ID=1 This record of . in addition , newest MySQL The interview questions are sorted out , You can Java Interview library applet online brush questions .

This line was successfully updated , The number of affected lines is 1, Taken for granted , Then put this update Statement again :

Now , The number of affected rows returned is 0, in other words , When the record to be updated is the same as the old value of the original record ,mysql In fact, there will be no update ..
In other words , If the data transmitted from the upstream , Equal to the old value of the database itself , When there is no change ,update The number of lines affected by the statement is 0. This is different from another scenario :" Update a record that doesn't exist , Affect the number of rows and return 0" Indistinguishable .

Conclusion : Do not use update The number of lines affected by the statement makes important business judgments !


Spring Boot After the scheduled task is started , How to stop automatically ?
Java 8 Sort of 10 A pose , What a show !
23 Design mode and Practice ( Very comprehensive )
Spring Boot Protect sensitive configurations 4 Methods !
Face a 5 year Java, Neither thread can exchange data !
Why does Ali recommend LongAdder?
A new technical director : No code writing with headphones ..
Don't use it. System... It's time ,StopWatch Good use of explosion !
Java 18 Official release ,finalize deprecated ..
Spring Boot Admin Born in the sky !
Spring Boot Learning notes , This is so complete !
Focus on Java Technology stack, see more dry goods


obtain Spring Boot Practical notes !
边栏推荐
- Solve the problem of "unexpected status code 503 service unavailable" when kaniko pushes the image to harbor
- rclone常用子命令中文解释
- Docker 安装部署Redis
- ctfshow-web354(SSRF)
- K8s set up redis cluster
- 清除过期缓存条目后可用空间仍不足 - 请考虑增加缓存的最大空间
- 产品学习(一)——结构图
- 8 figures | analyze Eureka's first synchronization registry
- ESP32 ESP-IDF ADC监测电池电压(带校正)
- Is fixed investment fund a high-risk product?
猜你喜欢

【推荐技术】基于协同过滤的网络信息推荐技术matlab仿真

How to enter the Internet industry and become a product manager? How to become a product manager without project experience?

Esp32 esp-idf GPIO key interrupt response

【图像处理】图像直方图均衡化系统含GUI界面

ESP32 - ULP 协处理器在低功耗模式下读片内霍尔传感器HALL SENSOR

(上)苹果有开源,但又怎样呢?

Why did grayscale fall from the altar?

盘点华为云GaussDB(for Redis)六大秒级能力

发现了一个 MySQL 的巨坑:update 更新别再用影响行数做判断了!!!
![[Electrical dielectric number] electrical dielectric number and calculation considering HVDC and facts components](/img/7c/2b1d4797f367cced51f36e8a1bb199.png)
[Electrical dielectric number] electrical dielectric number and calculation considering HVDC and facts components
随机推荐
[wechat applet] view container and basic content components
The game is real! China software cup releases a new industrial innovation competition, and schools and enterprises can participate in it jointly
Programming examples of stm32f1 and stm32subeide infrared receiving and decoding of NEC protocol
[image processing] image histogram equalization system with GUI interface
Problem: officeexception: failed to start and connect (II)
Dirty reading, unreal reading and unrepeatable reading
Is it suitable for girls to study product manager? What are the advantages?
【计网】(一) 集线器、网桥、交换机、路由器等概念
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
How to permanently configure local opencv4.5.5 for vs2019
Spark入门(一篇就够了)
如何进入互联网行业,成为产品经理?没有项目经验如何转行当上产品经理?
如何画产品架构图?
Is the account opening of GF Securities safe and reliable? How to open GF Securities Account
Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
[lingo] find the shortest path problem of undirected graph
rclone配置minio及基本操作
[Electrical dielectric number] electrical dielectric number and calculation considering HVDC and facts components
树莓派4的WiFi设置
在支付宝上买基金安全吗?哪里可以买基金