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?
- A. Only for joining a table with itself
- B. Only when no index exists on either table
- C. Never; hash join always dominates
- 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
- A transaction executes BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE…
- A relation R(A, B, C, D, E) has candidate key AB and no other candidate keys. Which of the following dependencies, if it existed, would…
- A relation R(A, B, C, D) has candidate key AB. If C and D are both non-prime, and B → C holds (B alone, part of the key, determines C)…
- A query optimizer estimates the selectivity of WHERE age = 30 using a histogram on the age column rather than assuming a uniform…
- A table has 1,000,000 rows, and a column's selectivity (distinct values / total rows) is estimated as 1/100,000. Roughly how many rows…
- A B+ tree index on a column is said to have a 'fan-out' of 100 (each internal node has up to 100 children). For a table with 10,000,000…