Monday, February 9, 2009

Difference between hash join and merge join

Oracle performs different types of joins on the rows of different tables in the database. In which merge join and hash join are famous.

Merge Join:

Oracle perfoms join between two different sets of row data of a table using the merge join algorithm. For these inputs are two seperate sets of rows and output is the result of join. Oracle reads input from both rows in an alternate fashion and meging together matching rows in order to generate output . The two inputs are sorted on join column.

Hash Join:

Oracle perfoms join between two different sets of row data of a table using the hash join alogrithm. For these inputs and output are same as merge join. Oracle reads all rows from the second input and builds a hash structure (like HashTable in java) before reading each row from the first input one at a time. For each row from the fist input ,the hash structure is probed and matching rows generate output.

No comments: