Mysql UPDATE递增

发布于 2024-09-17 08:04:02 字数 141 浏览 1 评论 0原文

MySQL UPDATE 递增操作事务安全吗?我的意思是,当许多并发客户端执行诸如“UPDATE table SET field=field+1”之类的查询时,是否有可能进入竞争条件?如果 1000 个客户端同时执行这样的查询,该字段将设置什么值,比以前大 1000?

Is MySQL UPDATE incrementing operation transaction-safe? I mean could it possible to get into the race condition while many concurrent clients execute queries like "UPDATE table SET field=field+1"? If 1000 clients will execute such query simultaneously, what value that field will be set, 1000 greater than before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抠脚大汉 2024-09-24 08:04:06

是的。每个 Update 语句都会锁定整个表 (MyISAM) 或单个行 (InnoDB),其他语句会排队直到锁被释放。

现在,如果您在事务中运行这些语句中的每一个,您实际上可能会遇到死锁。

Yes. Each Update statement locks either entire table (MyISAM) or a single row (InnoDB) and other statements are queued until the lock is released.

Now, if you run each of these statements in transaction, you might actually run into a deadlock.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文