CS FundamentalsVery hardProduct company interview · GATE level

Relations R (1000 blocks) and S (200 blocks) are joined with a block nested-loop join using M = 52 buffer blocks: M - 2 blocks hold a chunk of the outer relation, one block scans the inner relation and one collects output. The cost in block reads is b(outer) + ceil(b(outer)/(M - 2)) x b(inner). What is the cheapest cost obtainable by choosing the outer relation well?

  1. A. 5000 block reads
  2. B. 4200 block reads
  3. C. 200,200 block reads
  4. D. 1200 block reads

Correct answer: B. 4200 block reads

With S as the outer relation: 200 + ceil(200/50) x 1000 = 200 + 4 x 1000 = 4200. With R as the outer relation: 1000 + ceil(1000/50) x 200 = 1000 + 20 x 200 = 5000. The smaller relation should be the outer one because it needs fewer passes over the inner relation. 200,200 is the cost with only one buffer block for the outer relation (200 + 200 x 1000); 1200 would need the whole of S to fit in memory at once.

More DBMS and SQL questions

Exams that ask this topic