当前位置:网站首页>乐观锁批量跟新 纯SQL
乐观锁批量跟新 纯SQL
2022-08-01 20:22:00 【Q z1997】
今天同事问了我一个问题, 乐观锁下如何批量的更新数据 需求如下:
我想了一下 没有什么特别好的方案 讨论了一下 这样的一个sql 可以完成 上述需求的更新 SQL如下:
UPDATE emp
SET del_flag = 1,
record_version = record_version + 1
WHERE
( id, record_version ) IN ( ( 1, 4 ), ( 2, 6 ) )
and del_flag = 0
执行结果
中午和几个朋友讨论了一下 这样写有以下几个问题
- 更新的数据越多 乐观锁版本号的冲突的肯能就越大 这样的写法 相对与把 一个细颗粒的锁 粗话成了一个粗颗粒的锁 在高并发下不建议这样写了
- sql in 条件更新 索然是主键 但是条数过多 或者 数据聚散关系过大 都有可能不走索引 导致sql 新能问题
- 当然如果在并发量不大的前提下 更新条数也可控 这样写也是一个不错的方案
边栏推荐
猜你喜欢

算法---解码方法(Kotlin)

SIPp 安装及使用

To promote energy conservation institute 】 【 the opinions of the agricultural water price reform

第60章 ApplicationPart自动集成整体性和独立性插件项

XSS range intermediate bypass

Interview Blitz 70: What are sticky packs and half packs?How to deal with it?

The graphic details Eureka's caching mechanism/level 3 cache

使用微信公众号给指定微信用户发送信息

【无标题】

环境变量,进程地址空间
随机推荐
我的驾照考试笔记(1)
58: Chapter 5: Develop admin management services: 11: Develop [admin face login, interface]; (not measured) (using Ali AI face recognition) (demonstrated, using RestTemplate to implement interface cal
终于有人把AB实验讲明白了
我的驾照考试笔记(4)
57: Chapter 5: Develop admin management services: 10: Develop [get files from MongoDB's GridFS, interface]; (from GridFS, get the SOP of files) (Do not use MongoDB's service, you can exclude its autom
数据可视化
nacos安装与配置
The graphic details Eureka's caching mechanism/level 3 cache
作为程序员你应该会的软件
Oracle排序某个字段, 如果这个varchar2类型的字段有数字也有文字 , 怎么按照数字大小排序?
【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)
外骨骼机器人(七):标准步态数据库
The configuration manual for the secondary development of the XE training system of the missing moment document system
Compose实战-实现一个带下拉加载更多功能的LazyColumn
【luogu P1912】诗人小G(二分栈)(决策单调性优化DP)
18、分布式配置中心nacos
Determine a binary tree given inorder traversal and another traversal method
大神经验:软件测试的自我发展规划
【Untitled】
Remove 360's detection and modification of the default browser