# Rocksdb Queries
__*RocksDB Query*__
__*RocksDB Read*__
__*Long filter*__
__*Bloom Filter*__
__*Block Cache*__

![left](./student-guide/diagram/RocksDBQuery_aa_001_20220511.png)

------------------------------------------------------------
The data is stored in RockSDB, so the query of the data also needs to be completed through RocSkDB. Let's first understand the query operation of RocksDB. The query operation is slower than the B+ tree. The query operation needs to read MemTable, immutable MemTable, SSTable0, SSTable1... You need to iterate through all the collections in reverse order, and because of the write order and merge order, the data in the collection with the lower ordinal number must be newer than the data in the collection with the larger ordinal number. Therefore, once the data to be read is matched during this reverse traversal process, it must be the latest data, as long as the data is return. But if one piece of data does not exist in all data sets, it will be repeated in vain.

So it seems that the read operation is still rather cumbersome, and RocksDB uses the Bloom Filter to speed up the read operation. When the Bloom Filter determines that there is no data to read in the corresponding SSTable, the SSTable is skipped.

Note: Bloom Filter is actually a very long binary vector and a series of random mapping function. The Bloom Filter can be used to retrieve whether an element is in a collection. Its advantage is that the spatial efficiency and query time are far superior to normal algorithms, and the disadvantage is that it has a certain misidentification rate. To put it plainly, it is that the Bloom filter determines the elements of this collection are not necessarily in the collection, but if the Bloom Filter determines that it is not there, it must not be there.

Finally, RocksDB also has a Block Cache function. We can set a space in memory to Block Cache. This block cache contains data that we often access, so the query operation will prefer to read data from Block Cache. If the data is not cached to Block Cache, then let's start the read process described above from MemTable.























