cyningsun opened a new issue, #3169:
URL: https://github.com/apache/kvrocks/issues/3169

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/kvrocks/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:
   
   ```cpp
   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?
   
   - [x] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to