当前位置:网站首页>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 !
边栏推荐
- Product learning (II) - competitive product analysis
- Spark入门(一篇就够了)
- 【计网】(一) 集线器、网桥、交换机、路由器等概念
- 关于“2022年度网络安全教育线上培训”相关问题的复盘和说明
- 【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
- go-etcd
- Esp32 - ULP coprocessor reading Hall sensor in low power mode
- ESP32 ESP-IDF ADC监测电池电压(带校正)
- Docker 安装部署Redis
- The game is real! China software cup releases a new industrial innovation competition, and schools and enterprises can participate in it jointly
猜你喜欢

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

如何画产品架构图?
![[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines](/img/34/d2efae5b283cdc130d55f52cdff76d.png)
[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines

Product learning (III) - demand list

Esp32 - ULP coprocessor reading Hall sensor in low power mode

TDB中多个model情况下使用fuseki查询

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

8 张图 | 剖析 Eureka 的首次同步注册表

女生适合学产品经理吗?有什么优势?

ESP32在电池供电时用ULP监测电池电压
随机推荐
Solve the problem that the class defined in meta-inf.services cannot be read
STM32F1与STM32CubeIDE编程实例-NEC协议红外接收与解码
【电气介数】电气介数及考虑HVDC和FACTS元件的电气介数计算
【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
Which securities company does qiniu school cooperate with? Is it safe to open an account?
Jena基于OWL的默认推理查询
发现了一个 MySQL 的巨坑:update 更新别再用影响行数做判断了!!!
Esp32 - ULP coprocessor reading Hall sensor in low power mode
图解事件坐标screenX、clientX、pageX, offsetX的区别
记一次线上接口慢查询问题排查
在长城证券上做基金定投安全吗?
产品学习(二)——竞品分析
DC-4靶机
JSP - 分页
Dirty reading, unreal reading and unrepeatable reading
Software engineering review
Database notes
问题:OfficeException: failed to start and connect(三)
On whether variables are thread safe
Understand esp32 sleep mode and its power consumption