MySQL 中的嵌套循环
在此 O'Reilly 演示文稿中,有一段介绍了理解 MySQL 的 EXPLAIN 的一些关键概念:
什么是 JOIN?
- 一切都是 JOIN,因为 MySQL 总是使用嵌套循环
- 即使是单表 SELECT、UNION 或子查询
谁能解释这对于单表 SELECT 是如何工作的?
In this O'Reilly presentation, there is a paragraph introducing some key concepts for understanding MySQL's EXPLAIN:
What is a JOIN?
- Everything is a JOIN, because MySQL always uses nested-loops
- Even a single-table SELECT or a UNION or a subquery
Can anyone explain how this works for a single table SELECT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌套循环是处理连接的一种方式:
可以通过索引进行相当多的优化,通过“针对某个索引中键 K 处找到的每一行”而不是“表 A 的每一行”,对于表 B 也是如此。
演示文稿说这是 MySQL 处理连接的唯一方式。还有其他方法可以使用,但 MySQL 没有实现它们。此 OraFAQ 条目提供了 Oracle 实现的几个: http://www.orafaq.com/tuningguide/ join%20methods.html 类似: http://oracle-online-help.blogspot.com/2007/03/nested-loops-hash-join-and-sort-merge.html
“一切都是联接”是我相信这只是一个实施细节。其实没那么重要。
Nested loops is one way of processing joins:
That can be optimized with indexes quite a bit, by doing "for each row found at key K in some index" instead of "each row of table A", and the same with table B.
The presentation is saying this is the only way MySQL processes joins. There are other methods than can be used, but MySQL doesn't implement them. This OraFAQ entry gives several that Oracle implements: http://www.orafaq.com/tuningguide/join%20methods.html Similarly: http://oracle-online-help.blogspot.com/2007/03/nested-loops-hash-join-and-sort-merge.html
"Everything is a join" is just an implementation detail, I believe. Not really that important.