#34054·yugabyte-db

[DocDB] DocKey decode formats an error message for every non-DocKey key passed to DocKey::EncodedSize

Author: ttyusupovCreated Sep 18, 2026Updated Sep 18, 2026
Labelskind/enhancementarea/docdbpriority/medium

Jira Link: DB-23659

Description

DocKey::EncodedSize returned formatted status error message when decoding fails: ConsumePrimitiveValuesFromKey prepends a hex dump of the whole key, DocKey::DoDecode prepends one more message and KeyEntryValue::DecodeKey formats its own message with ToShortDebugStr. This is what we want for callers which return the status to the client or log it. But some callers treat a failed decode as a normal outcome and drop the status, so the message is built and thrown away for every non-DocKey key:

  • DocKeyComponentsExtractor::Transform and HashedDocKeyUpToHashComponentsExtractor::Transform in docdb_filter_policy.cc - bloom filter key transformers, called for every key during SST file build and for every seek when the filter is checked.
  • TryExtractDocKey in ql_rocksdb_storage.cc - sample blocks bounds for block-based sampling, called for every index entry of the tablet during ANALYZE.
  • PgApiImpl::IsValidYbctid - called for every ybctid literal in TID scan.

Intents DB reverse index keys start with kTransactionId and are not DocKeys, so before #33910 about half of the entries in every intents DB flush failed the decode inside the filter policy. Profile of intents DB flush on the base commit of #33910, rocksdb:high threads, inclusive CPU time:

80.9%  rocksdb::BlockBasedTableBuilder::Add
74.7%  docdb::DocKeyComponentsExtractor::Transform
74.3%  dockv::DocKey::EncodedSize
73.6%  dockv::ConsumePrimitiveValuesFromKey
63.9%  yb::Slice::ToDebugHexString
 6.1%  dockv::KeyEntryValue::DecodeKey
 3.9%  snappy::Compress
 0.8%  rocksdb::FixedSizeFilterBitsBuilder::AddKey

Each ~38MB intents DB flush took 2.6s, about 2s of that is formatting of error messages which nobody reads, while adding keys to the bloom filter takes less than 1% of the flush.

#33910 stopped installing the filter policy for intents DB, so this path is no longer hot. The regular DB filter policy, sampling and ybctid validation still format an error message on every decode failure.

Idea:

  • Add DocKey::TryGetEncodedSize and DocKey::TryGetEncodedSizeAndHashPresent which return std::nullopt on failure and don't describe the input.
  • Use them from the callers listed above. EncodedSize keeps the description for callers which propagate the status.

Issue Type

kind/enhancement

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.