The nested loops join, also called nested iteration, uses one join input as the outer input
table(shown as the top input in the graphical execution plan) and one as the inner (bottom)
input table.The outer loop consumes the outer input table row by row. The inner loop, executed
for each outer row, searches for matching rows in the inner input table.In the simplest case,
the search scans an entire table or index; this is called a naive nested loops join.If the search
exploits an index, it is called an index nested loops join.If the index is built as part of the query
plan (and destroyed upon completion of the query),it is called a temporary index nested loops join.
All these variants are considered by the query optimizer.A nested loops join is particularly effective
if the outer input is quite small and the inner input is preindexed and quite large. In many small
transactions, such as those affecting only a small set of rows, index nested loops joins are far
superior to both merge joins and hash joins.In large queries,however, nested loops joins are
often not the optimal choice.【摘自technet】
嵌套循环连接,也被称作嵌套迭代,用于连接外部输入表(显示为图形执行计划的顶部输入)和内部输入表的输入
。外部循环按照行检索外部输入表。内部循环,执行外部的每一行,查询内部输入表匹配的行。最简单的情况,查
询扫描整个表或者索引;这叫做纯嵌套循环连接。如果查询利用了索引,被称为索引嵌套循环连接。如果索引作为
查询计划的一部分被构建,这被称作临时索引嵌套循环连接。所有这些变体都会被查询优化器考虑到。当外部输入
非常小并且内部输入很大且预先添加过索引的时候嵌套循环连接是非常有效的。在许多小的转换中,比如仅仅影响
很小的行集的情况。索引嵌套连接是远远优于合并连接和哈希连接的。然而,在大数据的查询情况下,嵌套循环连
接通常不是最好的选择。