如果单行更新基于多个行状态,如何实现并发
我需要在表中更新一行。但是,该更新基于同一表中其他几行的状态。换句话说:在业务逻辑中,每行都取决于相邻行。
简化算法如下:
- 选择必须更新的表中的一个特定行,
- 行将用于1
- 同一表中选择几行,该
- 。
从 如果其他用户同时更新了2。的行,则该行仍将进行更新,因为“无读”行没有并发检查。
尽管实际上只有一个正在更改,但我发现只需更新所有行。但是,也许还有另一种更优雅的方法可以实现这一目标?
I need to update a single row in a table. The update, however, is based on the state of several other rows in the same Table. In other words: in business logic every row depends on neighboring rows.
Simplified algorithm is as follows:
- Select one particular row in a Table that has to be updated,
- Select several rows from the same Table, which will be used for the 1. update validation
- Validate
- Update only the row from 1.
This poses a concurrency problem where if some rows from 2. are updated in the mean time by other user, the row from 1. is still going to be updated, as there is no concurrency check on "read-only" rows.
I figured out to just update all rows despite only one is actually being changed. But maybe there is another, more elegant way to achieve this goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论