CS FundamentalsHardProduct-company MCQ pattern
Which statement about a query execution plan using a hash join versus a nested-loop join is correct?
- 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
- B. Hash joins can only be used with inequality conditions, never equality
- C. Nested-loop joins never use an index
- 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
- 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…
- 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…