Join Algorithm

Join Algorithm

Nested Loops JoinMerge JoinHash Join
DefinitionFor each row in the first table (outer loop), the database system searches through the second table (inner loop) to find matching rowsUsed when both input tables are sorted on the join key. The database engine reads through both tables simultaneously, like merging two sorted lists, and outputs matching pairsBuilding a hash table on the join key of one of the tables (usually the smaller one) and then scanning the other table to find matching rows by looking into the hash table
Best Use CaseSmall datasets or when one table is much smaller than the otherLarge, sorted datasetsLarge, unsorted datasets
PerformanceCan be slow for large datasets, but fast for small to medium datasets with indexesVery efficient if data is sorted on join columnsFast for large datasets, but requires more memory
Memory UsageLow, since it processes one row at a timeModerate, depending on the size of the datasetsHigh, due to the creation of a hash table