Nested loop join
Computing algorithm
A nested loop join is a naive algorithm that joins two relations by using two nested loops. Join operations are important for database management.
01Algorithm
Two relations and
are joined as follows:
This algorithm will involve nr*bs+ br block transfers and nr+br seeks, where br and bs are number of blocks in relations R and S respectively, and nr is the number of tuples in relation R.
The algorithm runs in I/Os, where
and
is the number of tuples contained in
and
respectively and can easily be generalized to join any number of relations ...
The block nested loop join algorithm is a generalization of the simple nested loops algorithm that takes advantage of additional memory to reduce the number of times that the relation is scanned. It loads large chunks of relation R into main memory. For each chunk, it scans S and evaluates the join condition on all tuple pairs, currently in memory. This reduces the number of times S is scanned to once per chunk.
02Index join variation
If the inner relation has an index on the attributes used in the join, then the naive nest loop join can be replaced with an index join.
algorithm index_join is for each tuple r in R do for each tuple s in S in the index lookup do yield tuple <r,s>The time complexity for this variation improves from
Sources and credits
This article is adapted from the Wikipedia article “Nested loop join”, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.
Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.