Database / RocksDB Basics Interview Questions
What is a Comparator in RocksDB?
A Comparator defines how RocksDB orders keys, determining what "sorted" actually means for a given database or column family.
- The default comparator sorts keys as raw bytes, in straightforward lexicographic order
- Applications can supply a custom comparator to sort keys differently, for example treating a numeric portion of the key numerically rather than as raw bytes
- Once a database is created with a particular comparator, that choice generally can't be changed without rebuilding the database
Because so much of RocksDB's internal structure, from MemTables to SSTables, depends on maintaining sorted order, the comparator is a foundational, largely fixed choice made early in a database's life.
More Related questions...