Indexes: B-Trees and the Cost of a Lookup · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Indexes: fast lookups at a write cost

Computing · Data & Databases · ages 19-20
Name ______________________   Date ____________
  1. Why are B-tree nodes wide rather than binary?

    • Keys share a read
    • Wide nodes use less storage
    • Wide nodes skip all write costs
  2. A users table has an index on email and no other index. Which lookup does the index speed up?

    • Finding users older than 30
    • One email lookup
    • Grouping users by country
  3. Which cost does every index add?

    • Slower but correct results
    • Extra rows in answers
    • Write work plus storage
  4. A table with five indexes inserts slowly. What is the likely cause?

    • Five index writes per insert
    • The disk reads pages too quickly
    • Too few queries use the table
  5. The email index stores values in order. Which extra query can use it?

    • Counting rows by country
    • Averaging all ages
    • Email names from a to m
  6. A B-tree index helps only exact matches, never ranges.

    Circle one:   True   False

  7. An index on city helps a query that filters rows by city and sorts by city.

    Circle one:   True   False

  8. Jo wants an index on every column to make all queries fast. What is wrong with the plan?

    • Queries would return wrong rows
    • Write and storage tax per index
    • Two indexes cannot share one table
LightMySky · lightmysky.comW1-mt_1Z5EQTqooI-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Indexes: fast lookups at a write cost W1-mt_1Z5EQTqooI-s1

  1. Keys share a read · A node fills a disk page, and the disk reads a page at a time.
  2. One email lookup · The index covers email only, so only the email lookup can use it.
  3. Write work plus storage · Each write must update every index, and each index occupies space.
  4. Five index writes per insert · Write work grows with each index, so heavy indexing slows inserts.
  5. Email names from a to m · Order serves ranges, so a range over email can use the same index.
  6. False · Its keys stay ordered, so ranges and sorts benefit too.
  7. True · One ordered structure serves both the filter and the sort.
  8. Write and storage tax per index · Each index speeds its own lookups but charges on every write.
Worksheet · LightMySky