Why do LSM stores keep a Bloom filter for each sorted file, and what does it save?
Sketch your own answer first, then compare it with the one below.
A strong answer
A read for an absent key has to be ruled out in every file. Each check is a block read from disk. With many files, a miss costs many reads.
A small in-memory filter per file answers "definitely not here" for nearly every file that lacks the key. The read skips those files. Only the file that holds the key, and the rare file with a false positive, is read.
The filter costs memory, about ten bits per key for a rate near one in a hundred. It does not help range scans, because a filter answers membership of one key, not order. A good answer says that.
Sources
- Fay Chang, Jeffrey Dean, Sanjay Ghemawat, Wilson C. Hsieh, Deborah A. Wallach, Mike Burrows, Tushar Chandra, Andrew Fikes, Robert E. Gruber (2008). Bigtable: A Distributed Storage System for Structured Data.
- Chen Luo, Michael J. Carey (2020). LSM-based storage techniques: a survey.