<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Nested_loop_join</id>
	<title>Nested loop join - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Nested_loop_join"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Nested_loop_join&amp;action=history"/>
	<updated>2026-10-24T18:49:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Nested_loop_join&amp;diff=3756796&amp;oldid=prev</id>
		<title>imported&gt;Avocado: Adding short description: &quot;Computing algorithm&quot;</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Nested_loop_join&amp;diff=3756796&amp;oldid=prev"/>
		<updated>2025-05-18T20:42:11Z</updated>

		<summary type="html">&lt;p&gt;Adding &lt;a href=&quot;https://en.wikipedia.org/wiki/Short_description&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Short description&quot;&gt;short description&lt;/a&gt;: &amp;quot;Computing algorithm&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Computing algorithm}}&lt;br /&gt;
{{More citations needed|date=January 2021}}&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;nested loop join&amp;#039;&amp;#039;&amp;#039; is a naive [[algorithm]] that joins two relations by using two nested [[loop (computing)|loop]]s.&amp;lt;ref&amp;gt;{{cite web | url=https://technet.microsoft.com/en-us/library/ms191318(v=sql.105).aspx | title=Understanding Nested Loops Joins | date=4 October 2012 }}&amp;lt;/ref&amp;gt; Join operations are important for [[database]] management.&lt;br /&gt;
&lt;br /&gt;
==Algorithm==&lt;br /&gt;
Two relations &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; are joined as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;algorithm&amp;#039;&amp;#039;&amp;#039; nested_loop_join &amp;#039;&amp;#039;&amp;#039;is&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;for each&amp;#039;&amp;#039;&amp;#039; tuple &amp;#039;&amp;#039;r&amp;#039;&amp;#039; in &amp;#039;&amp;#039;R&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;for each&amp;#039;&amp;#039;&amp;#039; tuple &amp;#039;&amp;#039;s&amp;#039;&amp;#039; in &amp;#039;&amp;#039;S&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
             &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;r&amp;#039;&amp;#039; and &amp;#039;&amp;#039;s&amp;#039;&amp;#039; satisfy the join condition &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
                 &amp;#039;&amp;#039;&amp;#039;yield&amp;#039;&amp;#039;&amp;#039; tuple &amp;lt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;,&amp;#039;&amp;#039;s&amp;#039;&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This algorithm will involve  n&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt;*b&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt;+ b&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; block transfers and n&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt;+b&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; seeks, where b&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and b&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are number of blocks in relations R and S respectively, and n&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; is the number of tuples in relation R.&lt;br /&gt;
&lt;br /&gt;
The algorithm runs in &amp;lt;math&amp;gt;O(|R||S|)&amp;lt;/math&amp;gt; I/Os, where &amp;lt;math&amp;gt;|R|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt; is the number of tuples contained in &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; respectively and can easily be generalized to join any number of relations ...&lt;br /&gt;
&lt;br /&gt;
The [[block nested loop]] join algorithm&amp;lt;ref&amp;gt;{{Cite web| title=Query Processing Overview | url=http://www.databaselecture.com/slides/9_Operator_Implementations.pdf | archive-url=https://web.archive.org/web/20210730081820/http://databaselecture.com/slides/9_Operator_Implementations.pdf | archive-date=2021-07-30}}&amp;lt;/ref&amp;gt; is a generalization of the simple nested loops algorithm that takes advantage of additional [[memory (computing)|memory]] to reduce the number of times that the &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Index join variation==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;algorithm&amp;#039;&amp;#039;&amp;#039; index_join &amp;#039;&amp;#039;&amp;#039;is&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;for each&amp;#039;&amp;#039;&amp;#039; tuple &amp;#039;&amp;#039;r&amp;#039;&amp;#039; in &amp;#039;&amp;#039;R&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;for each&amp;#039;&amp;#039;&amp;#039; tuple &amp;#039;&amp;#039;s&amp;#039;&amp;#039; in &amp;#039;&amp;#039;S&amp;#039;&amp;#039; in the index lookup &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
             &amp;#039;&amp;#039;&amp;#039;yield&amp;#039;&amp;#039;&amp;#039; tuple &amp;lt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;,&amp;#039;&amp;#039;s&amp;#039;&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The time complexity for this variation improves from &amp;lt;math&amp;gt; O(|R||S|) \text{ to } O(|R|\log|S|) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Hash join]]&lt;br /&gt;
*[[Sort-merge join]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Nested Loop Join}}&lt;br /&gt;
[[Category:Join algorithms]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{compu-sci-stub}}&lt;/div&gt;</summary>
		<author><name>imported&gt;Avocado</name></author>
	</entry>
</feed>