Try
↑ ↓ move↵ openesc close
In this lesson · topic 3 of 7
  1. 1. Finding one row without reading them all
  2. 2. Secondary indexes and Bloom filters
  3. 3. Tune a filter and add indexes
  4. 4. Each index is a tax on every write
  5. 5. Bits per key against false positives
  6. 6. Where filters help and where they do not
  7. 7. False positives, hashes and index cost

Topic 3

Tune a filter and add indexes

8 min read

Two experiments in one lab

The top half fills a Bloom filter with keys. After each tick it asks the filter about 10,000 keys that were never added and counts the ones that pass. That is the measured false positive rate. Next to it is the formula’s value. The chart shows the formula’s rate at full load for every bits-per-key setting.

The bottom half is a table with secondary indexes. Each insert adds a row and an entry in every index. It counts the pages that must be written, and compares a scan with an index lookup.

Predict before you press play

You cut a filter from 10 bits per key to 5. What happens to the false positive rate?

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.

Full-page version with guided experiments: Bloom filters and indexes lab.

Things to try

  1. Leave 10 bits and 7 hashes and compare the measured rate with the formula.
  2. Drop to 4 bits per key and 3 hashes.
  3. Keep 10 bits and use one hash, then twelve.
  4. Set secondary indexes to 0 and read page writes per insert.
  5. Set it to 5 and read it again.

The full-page lab has guided experiments for each of these.

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