How Nested Loop JOIN Works [ID 263517.1]

Applies To

Oracle Server - Enterprise Edition - Version: 8.1.7 to 9.2.0.4
Information in this document applies to any platform.

Goal

This article explains how a nested loop join works.

Fix

A nested loop join is the simplest join technique.

Let R and S be the two relations (tables) to be joined.
And R is designated as outer table and S is inner table.

For each row 'r' of the outer table, all rows 's' of inner table are read and compared with the row from the outer table. Whenever the join condition is satisfied, the two rows are concatenated to form. a row which is placed in an output relation.

In simplest words, each row of the cartesian product R x S is tested on the join condition. If it it satisfied then it is included into the join result.

Hence, for a nested loop join to occur, a where clause is not always needed.

The algorithm for the same is as follows:

for each row r belongs to R
for each row s belongs to S
if r and s satisfy C then 
put (r concatenate s) in the output table
endif
end for
end for


Instead of retrieving one row each time, an entire block of tuples (rows) is read from disk and cached in main memory. This is more efficient because this way, several random accesses are replaced by sequential rows accesses which is faster. A further performance improving measure is to use the relation with the lowest cardinality as the outer relation in order to reduce the I/O costs which will be given by :

size of outer table + (size of outer table)*(size of the inner relation)

And this can be minimized if :

size of outer table <= size of inner table.

Furthermore, we can switch the direction in which the inner relation is read each time. This has the advantage that the last block read by the previous inner loop is the first block of the oncoming inner loop. It still is in a memory buffer and therefore doesn't need to read from disk.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/38267/viewspace-743198/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/38267/viewspace-743198/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值