如果单行更新基于多个行状态,如何实现并发

发布于 2025-02-09 04:00:25 字数 268 浏览 1 评论 0原文

我需要在表中更新一行。但是,该更新基于同一表中其他几行的状态。换句话说:在业务逻辑中,每行都取决于相邻行。

简化算法如下:

  1. 选择必须更新的表中的一个特定行,
  2. 行将用于1
  3. 同一表中选择几行,该

从 如果其他用户同时更新了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:

  1. Select one particular row in a Table that has to be updated,
  2. Select several rows from the same Table, which will be used for the 1. update validation
  3. Validate
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文