In this lesson · topic 6 of 7
Topic 6
Where filters help and where they do not
4 min read
What they are good for
A filter answers one question: might this key be here. It helps wherever a lookup that finds nothing is expensive, which means anywhere a check must be made against many places. An LSM tree checks many files. A distributed store may check many nodes. A cache in front of a slow database may use a filter to remember which keys exist, so a request for a missing key does not reach the database.
What they cannot do
A filter cannot answer a range. It has no order, so it cannot say whether any key between two values exists. A scan gets no help.
A plain filter cannot remove a key. Clearing a key’s bits could clear a bit that another key set, and that creates false negatives. An LSM tree does not need removal. A filter belongs to one immutable file, and it is dropped and rebuilt when the file is merged. Variants that support removal exist, and use more space.
A filter must be sized for the number of keys it will hold. Add too many and the set bits crowd out the zeros. At 10 bits per key the lab had 51%measured of bits set at full load. A filter filled well past its design size passes almost everything and does nothing.
The memory bill
A filter at 10 bits per key is 6,250 bytesmeasured for the lab’s 5000 keys. That is small next to the data, and is the reason filters are kept in memory for every file. The cost scales with the number of keys, so a store with billions of keys spends gigabytes on filters, and must choose how many bits to give.
Predict