Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-73649

Improve SBE plan cache BudgetEstimator to incorporate the size of the key

    • Query Optimization
    • Minor Change
    • QO 2023-06-12
    • 128

      The code for the SBE plan cache's BudgetEstimator currently looks like this:

      struct BudgetEstimator {
          /**
           * This estimator function is called when an entry is added or removed to LRU cache in order to
           * make sure the total plan cache size does not exceed the maximum size.
           */
          size_t operator()(const sbe::PlanCacheKey& key,
                            const std::shared_ptr<const PlanCacheEntry>& entry) {
              // TODO: SERVER-73649 include size of underlying query shape and size of int_32 key hash in
              // total size estimation.
              return entry->estimatedEntrySizeBytes;
          }
      };
      

      That is, we are only considering the size of the PlanCacheEntry as counting towards the plan cache's memory budget. However, the keys themselves can get quite large – they encode a query shape which can get large, in addition to a bunch of other flags and index descriminators and such. The fact that we are not considering the size of the key means we are underestimating the memory being used by the SBE plan cache, and potentially using more memory than allowed by the planCacheSize parameter configuration.

      Original description

      Currently, SBE Plan cache budget estimations only track the size of the query plans. To be most accurate, we should also track the size of the hashed key and the underlying query shape (from which the hash is generated). This should be completed before before or in tandem with SERVER-73659

            Assignee:
            matt.olma@mongodb.com Matt Olma
            Reporter:
            maddie.zechar@mongodb.com Maddie Zechar
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: