CS FundamentalsHardGATE

A sort-merge join requires both input relations to be sorted on the join key (or sorted as part of the plan). When is sort-merge join typically preferred over hash join?

  1. A. Only for joining a table with itself
  2. B. Only when no index exists on either table
  3. C. Never; hash join always dominates
  4. D. When the inputs are already sorted (e.g. via an existing index) or when the join condition is an inequality/range rather than pure equality, where hash join does not directly apply

Correct answer: D. When the inputs are already sorted (e.g. via an existing index) or when the join condition is an inequality/range rather than pure equality, where hash join does not directly apply

If data is already sorted (e.g. scanning a B+ tree index in key order) the extra sort step is free, making sort-merge attractive; sort-merge also naturally extends to range-based join conditions (e.g. a BETWEEN-style join), which a pure hash join (built for equality) cannot directly support.

More DBMS and SQL questions

Exams that ask this topic