CS FundamentalsHardProduct-company MCQ pattern

Which statement about a query execution plan using a hash join versus a nested-loop join is correct?

  1. A. A hash join is typically efficient for joining two large, unsorted tables with an equality condition (building a hash table on the smaller side), while a nested-loop join tends to be efficient when one side is small or there's a usable index for the inner lookup
  2. B. Hash joins can only be used with inequality conditions, never equality
  3. C. Nested-loop joins never use an index
  4. D. A nested-loop join always outperforms a hash join regardless of table sizes

Correct answer: A. A hash join is typically efficient for joining two large, unsorted tables with an equality condition (building a hash table on the smaller side), while a nested-loop join tends to be efficient when one side is small or there's a usable index for the inner lookup

Hash join builds an in-memory (or spill-to-disk) hash table on the smaller input keyed by the join column and probes it with the other input — efficient for equi-joins on large, unindexed data. Nested-loop join instead iterates the outer input and, for each row, searches the inner input (ideally via an index), which is cheap when the outer input is small or a selective index exists on the inner join column.

More DBMS and SQL questions

Exams that ask this topic