# RocksDB Queries

![`smart`](RocksDBQuery_aa_001_20220511.png)

-------------------------------------------------------------------
RocksDB uses a log-structured merge-tree (LSM tree) data structure to store data on disk, which allows for efficient writes and fast point lookups. However, the read operation can be slow, as it involves iterating through multiple SST files in reverse order to find the most recent data for a given key.

To improve the performance of read operations, RocksDB uses a Bloom filter to quickly determine whether a key is present in a given SST file. A Bloom filter is a probabilistic data structure that can efficiently test whether an element is a member of a set. It has the advantage of being highly space-efficient and fast to query, but it also has a certain false positive rate, which means that it can occasionally return a false positive result (i.e., it may indicate that a key is present in the SST file when it is actually not).

In addition to using a Bloom filter, RocksDB also has an internal feature called the Block Cache, which is a space in memory that is used to store data that is accessed frequently. When a read operation is performed, RocksDB first checks the Block Cache to see if the data is present there. If it is, the data is returned immediately. If it is not, the read operation proceeds as described above, starting with the MemTable and iterating through the SST files in reverse order.

Overall, the combination of a Bloom filter and a Block Cache allows RocksDB to efficiently and quickly perform read operations, even when dealing with large amounts of data.