当前位置:网站首页>乐观锁批量跟新 纯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 新能问题
- 当然如果在并发量不大的前提下 更新条数也可控 这样写也是一个不错的方案
边栏推荐
- 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
- WhatsApp group sending actual combat sharing - WhatsApp Business API account
- nacos installation and configuration
- Acrel-5010重点用能单位能耗在线监测系统在湖南三立集团的应用
- Custom command to get focus
- Greenplum数据库源码分析——Standby Master操作工具分析
- 【无标题】
- 启明云端分享|盘点ESP8684开发板有哪些功能
- 锐捷交换机基础配置
- 第57章 业务逻辑之业务实体与数据库表的映射规则定义
猜你喜欢

【kali-信息收集】(1.3)探测网络范围:DMitry(域名查询工具)、Scapy(跟踪路由工具)

Get started quickly with MongoDB

【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战

Greenplum数据库源码分析——Standby Master操作工具分析

WhatsApp group sending actual combat sharing - WhatsApp Business API account

Zheng Xiangling, Chairman of Tide Pharmaceuticals, won the "2022 Outstanding Influential Entrepreneur Award" Tide Pharmaceuticals won the "Corporate Social Responsibility Model Award"

idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换

终于有人把AB实验讲明白了

【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)

SIPp 安装及使用
随机推荐
通配符 SSL/TLS 证书
【kali-信息收集】(1.3)探测网络范围:DMitry(域名查询工具)、Scapy(跟踪路由工具)
MongoDB快速上手
【Untitled】
Multithreaded producers and consumers
Buttons with good user experience should not have hover state on mobile phones
Digital twin Beijing the imperial palace, yuan universe is the process of tourism
泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
【kali-信息收集】(1.4)识别活跃的主机/查看打开的端口:Nmap(网络映射器工具)
Application of Acrel-5010 online monitoring system for key energy consumption unit energy consumption in Hunan Sanli Group
Win10, the middle mouse button cannot zoom in and out in proe/creo
【kali-信息收集】(1.5)系统指纹识别:Nmap、p0f
Intranet penetration lanproxy deployment
Custom command to get focus
18、分布式配置中心nacos
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
XSS靶场中级绕过
有序双向链表的实现。
【无标题】
二维、三维、四维矩阵每个维度含义解释