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.
| Series | Latest | Lowest | Highest |
|---|---|---|---|
| formula, 7 hashes | 0% | 0% | 99% |
| formula, best hash count | 0% | 0% | 63% |
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.
5,000 keys in a filter of 10 bits per key and 7 hashes. Measured false positive rate 0.90%, formula 0.82%. At 10 bits per key the formula at full load gives 0.82% with these hashes and 0.82% with 7. 2 secondary indexes cost 0.36 page writes per insert.
What to try
Each one sets up a starting point. Then make the change it describes.
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.
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.
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.
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.
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.
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