跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] 关于在业务中 MYSQL 事务查询的一个疑惑

发表于

我有一个疑问,在实际业务中,当我们使用 MySQL 进行查询时,某一瞬间得到的值在下一瞬间可能会发生变化。这是否意味着在某一瞬间拿到的值不够可靠?

举个例子,在仓库库存管理中,如果在查询时库存是 30 ,但在查询完成后,其他业务操作改变了库存,导致库存变为 25 。然而,业务处理时依旧基于查询时的库存 30 进行操作,这样就会导致记录流水的值出现误差。

目前我能想到的解决办法是:

使用乐观锁,通过在记录中添加版本号或时间戳字段,在更新数据时进行校验,确保数据的一致性。 使用悲观锁,在查询时锁定数据行,直到事务结束,防止其他事务修改数据。 除此之外,还有其他方式可以解决这个问题吗?例如,在确保数据一致性和处理准确性的前提下,有没有更高效或更适合实际业务场景的方法?

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.