CS FundamentalsVery hardGATE CS (PYQ pattern)

A table has 100,000 rows in 2500 pages, and a predicate selects 3% of the rows, which are spread uniformly at random over the pages. An unclustered B+ tree of height 3 (3 reads to the first leaf, leaf scanning ignored) is used, but the matching record ids are first sorted by page so each needed page is read only once. What is the expected cost of this plan, and is it cheaper than the 2500-page full scan?

  1. A. about 3003 reads; dearer
  2. B. about 1750 reads; cheaper
  3. C. about 2503 reads; dearer
  4. D. about 78 reads; cheaper

Correct answer: B. about 1750 reads; cheaper

3000 matching rows hit each page with probability 1 - (1 - 1/2500)^3000 = 1 - e^-1.2 = 0.699, so about 1747 distinct pages; plus 3 index reads gives about 1750 < 2500. Without sorting, each row costs a read: 3003. 78 assumes the matches are packed contiguously (clustered).

More DBMS and SQL questions

Exams that ask this topic