Skip to main content
InterviewHubPRO
Section Overview
Q30

Question 30 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

60%
PostgreSQL Enterprise (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

What is Hash Join vs Merge Join vs Nested Loop in query execution?

senior LevelpostgresqlAdvanced Internals

In Simple Words: The 3 fundamental Join algorithms evaluated by the query optimizer:

  1. Nested Loop: For each row in outer table, scans matching rows in inner table via index. Fastest when one table is small and inner table has a selective index.
  2. Hash Join: Loads the smaller table into an in-memory hash table in work_mem, then scans the larger table matching hash keys. Best for large unindexed equijoins.
  3. Merge Join: Both tables are sorted by the join key, then merged sequentially in a single pass. Best when both tables are large and already sorted by an index.