Ray's Knowledge Base

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#

  1. Build the end key as the key plus one zero byte.
  2. Delete the half-open range [key, key + "\0").
void delete_key(IndexWrite& w, Family family, std::string key) {
    std::string end = key;
    end.push_back('\0');
    w.delete_range(family, key, end);
}

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_plugin and clear_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.