1.嵌套循环连接:
这是一种物理联接算法,用于联接2个关系的情况。此联接是内部联接技术,这意味着我们看不到联接。这是所有类型的联接中最简单的。这是适用于小数据和小交易的最佳算法。对于名为R和S的2个关系,嵌套循环连接的算法如下:
For each record x of R read in, do
Use the index on B for S
Get all the matching records (having B=x.A)
End
2.哈希加入:
哈希联接也是一种物理联接算法,在内部联接两个表的情况下使用。联接是一种内部联接技术,这意味着我们看不到联接。联接选择由查询优化器自动完成。哈希联接使用两个步骤(构建和探测)执行。在两个关系分别为R和S的情况下,哈希联接的算法如下:
Hash records of R, one by one, using A values
(Use the same M buckets and same hash function h)
Hash matching pair of records into the same bucket
End
嵌套循环联接和哈希联接之间的区别:
S.No. | Nested Loop Join | Hash Join |
---|---|---|
1. | It is processed by forming an outer loop within an inner loop after which the inner loop is individually processed for the fewer entries that it has. | It is specifically used in case of joining of larger tables. |
2. | The nested join has the least performance in case of large tables. | It has best performance in case of large and sorted and non-indexed inputs. |
3. | There are two phases in this, outer and inner loop processing. | The two phases in this are build and probe. |
4. | Steps involved include identifying an outer driving table and assigning the inner table to it, and processing the rows of inner table for every outer table row. | The steps involved are building a Hash table on a small table. It is used to probe the hash value of the Hash table is applicable for each element in the second row. |
5. | Index range scan is done here. | Full-table scan of the smaller table is done in case of hash join. |
6. | This uses lesser RAM resources. | It uses more RAM resources. |
7. | It is the most common type of join. | It is not as common as the nested loop join. |
8. | Least number of comparisons are required in case of nested loop join. | It needs more comparisons than the nested loop join thereby using more RAM resources. |
9. | It is the fastest join algorithm due to least number of comparisons. | It is not as fast due to more number of comparisons. |
10. | It is better than all other types of join for small transactions and small data. | It is not as good as nested loop join in case of smaller data. |
11. | It is of three types, namely, nested loop join, indexed nested loop join and Temporary indexed nested loop join. | Its types are classic hash join, Grace hash join, hybrid hash join, hash anti join, hash semi-join, recursive hash join and hash bailout. |
12. | It is not automatically selected. | This join is automatically selected in case there is no specific reason to adopt other types of join algorithms. It is also known as the go-to guy of all the join operators. |