Skip to content

Performance Question: Could EXISTS command benefit from MultiGet optimization? #3169

@cyningsun

Description

@cyningsun

Search before asking

  • I had searched in the issues and found no similar issues.

Motivation

Summary

Hi! 👋 While exploring the codebase, I noticed the EXISTS command uses sequential Get operations, while other multi-key commands like MGET and MDEL use MultiGet. I'm wondering if this is intentional or if there might be a performance optimization opportunity here.

Current Implementation

Currently, Database::existsInternal() uses a sequential approach:

rocksdb::Status Database::existsInternal(engine::Context &ctx, const std::vector<std::string> &keys, int *ret) {
  *ret = 0;
  rocksdb::Status s;
  std::string value;
  for (const auto &key : keys) {  // Sequential Get operations
    s = storage_->Get(ctx, ctx.GetReadOptions(), metadata_cf_handle_, key, &value);
    if (!s.ok() && !s.IsNotFound()) return s;
    if (s.ok()) {
      Metadata metadata(kRedisNone, false);
      s = metadata.Decode(value);
      if (!s.ok()) return s;
      if (!metadata.Expired()) *ret += 1;
    }
  }
  return rocksdb::Status::OK();
}

What I observed

Other multi-key commands use MultiGet:

  • MDEL and MGET both use storage_->MultiGet() for batch operations
  • EXISTS uses a loop with individual Get calls

Questions

I'm curious about:

  1. Is there a specific reason EXISTS uses sequential Get instead of MultiGet?
  2. Would a MultiGet-based performance optimization be welcome?

Potential benefits

A MultiGet-based implementation could potentially provide:

  • Better performance through batch operations (fewer RocksDB calls)
  • Consistency with other multi-key commands (MGET, MDEL, etc.)

Code location

src/storage/redis_db.cc - Database::existsInternal() (lines 624-639)

Solution

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions