Try
↑ ↓ move↵ openesc close

Bloom filters and indexes lab

Fill a Bloom filter and measure its false positive rate against the formula, then add secondary indexes to a table and count what they do to the cost of a write.

keys 5,000 of 5,00010 bits per key, 7 hashesbest hash count here: 7

The Bloom filter

false positives, measured
0.90%
false positives, formula
0.82%
bits set
51%
filter size
6,250 bytes

The filter is sized for the full key count, so it starts empty and fills as keys arrive. It is asked about 10,000 keys that were never added. A yes for any of them is a false positive.

False positive rate at full load, by bits per key
False positive rate at full load, by bits per key. Text version available below the chart.0%25%50%75%100%11120bits per keyfalse positives

Secondary indexes on the table: 2

page writes per insert
0.36
lookup by that column, no index
157 pages
lookup with an index
4 pages

Each index is a tree of its own. A new row must touch a leaf page in every one of them. The page writes are counted at the same checkpoint spacing for all rows.

What to try

Each one sets up a starting point. Then make the change it describes.

  1. Ten bits per key

    Leave 10 bits per key and 7 hashes and compare the measured false positive rate with the formula.

    Look for. About one probe in a hundred for a missing key gets a wrong yes. The measured rate sits close to the formula, and half the bits are set.

  2. Starve the filter

    Drop to 4 bits per key with 3 hashes.

    Look for. The filter saves memory and many missing keys now pass it. The false positive rate climbs by an order of magnitude.

  3. Too few hashes

    Keep 10 bits per key but use one hash.

    Look for. Few bits are set, yet a single check is weak evidence. The rate is worse than with seven hashes. The best count is near 0.69 times the bits per key.

  4. Too many hashes

    Keep 10 bits per key and set the hashes to 12.

    Look for. Each key sets so many bits that the array fills up, and the rate gets worse again. More hashes help only up to a point.

  5. No secondary indexes

    Set secondary indexes to 0 and read the page writes per insert.

    Look for. The table appends rows to its last page, so an insert touches almost nothing new.

  6. Five indexes

    Set secondary indexes to 5.

    Look for. Every insert must also place an entry in five other trees, at random places. Page writes per insert climb many times over. Every lookup by an indexed column gets cheap, and every write pays for it.

New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms