MySQL InnoDB 对连接行进行锁定

发布于 2024-11-20 00:43:38 字数 230 浏览 6 评论 0原文

"SELECT ... FOR UPDATE" 是否锁定 MySQL 中的连接行?

如果是这样,是否可以禁用此行为?

文档中没有任何关于此的内容。我已经看到Oracle支持“SELECT ... FOR UPDATE OF table_name”其中table_name是主表或受影响的行将被锁定的连接表之一,但我从来没有在 MySQL 的上下文中看到了这一点。

Does "SELECT ... FOR UPDATE" lock joined rows in MySQL?

If so, is it possible to disable this behaviour?

There is nothing about this in the documentation. I've seen that Oracle supports "SELECT ... FOR UPDATE OF table_name" where table_name is the main table or one of the joined tables for which the affected rows will be locked, but I've never seen this mentioned in context with MySQL.

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

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

发布评论

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

评论(2

谁人与我共长歌 2024-11-27 00:43:39

请参阅此 MySQL 文档页面。它说:

锁定读取、更新或删除通常会在 SQL 语句处理中扫描的每个索引记录上设置记录锁。语句中是否存在排除该行的 WHERE 条件并不重要。

和:

对于 SELECT ... FOR UPDATE 或 SELECT ... LOCK IN SHARE MODE,会为扫描的行获取锁,并且预计会为不符合包含在结果集中的行释放锁(例如,如果它们不满足 WHERE 子句中给出的条件)。但是,在某些情况下,行可能不会立即解锁,因为结果行与其原始源之间的关系在查询执行期间丢失。

“扫描的行”是指连接中使用的任何表中的行。

See this MySQL doc page. It says:

A locking read, an UPDATE, or a DELETE generally set record locks on every index record that is scanned in the processing of the SQL statement. It does not matter whether there are WHERE conditions in the statement that would exclude the row.

and:

For SELECT ... FOR UPDATE or SELECT ... LOCK IN SHARE MODE, locks are acquired for scanned rows, and expected to be released for rows that do not qualify for inclusion in the result set (for example, if they do not meet the criteria given in the WHERE clause). However, in some cases, rows might not be unlocked immediately because the relationship between a result row and its original source is lost during query execution.

"scanned rows" refers to rows from any of the tables that are used in the join.

自此以后,行同陌路 2024-11-27 00:43:39

SELECT ... FOR UPDATE 锁定行和任何关联的索引条目,就像您为这些行发出 UPDATE 语句一样。

进而

如果启用自动提交,则不会锁定符合规范的行。

这个mySQL doc没有提供答案吗?

SELECT ... FOR UPDATE locks the rows and any associated index entries, the same as if you issued an UPDATE statement for those rows.

and then

If autocommit is enabled, the rows matching the specification are not locked.

Does this mySQL doc not provide the answers?

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