MySQL 视图的锁定行为?
我们正在考虑在我们的应用程序中使用 MySQL 合并视图,并在文档中遇到了以下令人费解的语言:
显式选择 TEMPTABLE 的一个原因是,在临时表创建之后、用于完成语句处理之前,可以释放基础表上的锁。这可能会导致比 MERGE 算法更快的锁定释放,以便使用该视图的其他客户端不会被阻塞太久。
我读这篇文章的方式是选择合并视图取出读锁,但这似乎不对。两个客户端可以像从表中一样同时从视图中读取数据吗?
谢谢!
We're considering using a MySQL merge view in our application, and came across the following puzzling language in the documentation:
A reason to choose TEMPTABLE explicitly is that locks can be released on underlying tables after the temporary table has been created and before it is used to finish processing the statement. This might result in quicker lock release than the MERGE algorithm so that other clients that use the view are not blocked as long.
The way I read this is that selects on merge views take out a read lock, but that doesn't seem right. Can two clients read from a view simultaneously the way they can from a table?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我读它的方式是,虽然它确实取出了锁(它必须读取数据,对吧?),但它会构建一个 TEMPTABLE,然后释放锁。此后要做的任何工作都可以在没有锁的情况下完成,因此其他客户端可以享受底层表的乐趣。
这样读锁可能会释放得更快。
The way I read it is that while it DOES take out a lock (it has to read the data, right?), it builds a TEMPTABLE, and then release the lock. Any work to be done after that can be done without the lock, and so the other clients can have their fun with the underlying tables.
The read lock might be released quicker this way.
如果在 MyISAM 表上创建视图,则 SELECT 和 UPDATE 是互斥的,因此表上的 SELECT/UPDATE 将阻止视图上的任何 UPDATE/SELECT。所以你想保持锁较短。
在 InnoDB 上,这不是问题。
If you create a view on MyISAM tables, SELECTs and UPDATEs are mutually exclusive, so a SELECT/UPDATE on the table would block any UPDATE/SELECT on the view. So you'd want to keep locks short.
On InnoDB, this is not a problem.