Delete exactly one key through a range-delete-only interface
RecipeVerified 27 Sep 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.
When to use#
Use this when a write interface offers delete_range(begin, end) but no single-key delete, for example a write abstraction shared by a RocksDB WriteBatch and an SST writer, and you must remove one key without removing the keys that start with it.
Do not use prefix_end(key) as the end: [key, prefix_end(key)) also covers every longer key that starts with key, such as name.a and name.ab for the key name.a.
Steps#
- Build the end key as the key plus one zero byte.
- Delete the half-open range
[key, key + "\0").
void
With the default bytewise comparator, key + "\0" is the smallest key that is greater than key. So the range holds only key itself.
Evidence#
- Used in dftracer-utils
records::clear_pluginandclear_path(src/dftracer/utils/index/store/index_write.cpp), where the path-keyed layout stores a file-level value under[prefix][path]with no trailing separator. - The plugin-extension tests (drop and rebuild one extension by name, while other names stay) and the full C++ suite (282 tests) passed with it.
- The reasoning depends on the bytewise comparator. A custom comparator can order keys differently; check it before you use this.