SQL & Relational Databases (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What are the three primary physical Join Algorithms (Nested Loop, Hash Join, Merge Join)?
senior Levelsql-databasesAdvanced Internals
In Simple Words:
- Nested Loop Join: Outer loop iterates through Table A, inner loop looks up Table B via index. Best for small outer table and indexed inner table.
- Hash Join: In-memory hash table is built from Table A on the join key. Table B is scanned, probing the hash table. Best for large unindexed equijoins.
- Sort-Merge Join: Both tables are sorted by join key, then merged in a single coordinated sequential scan. Ideal for large sorted tables.