summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Ignatyev <alexander.ignatyev@mongodb.com>2022-02-21 21:31:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-23 07:15:42 +0000
commit4fbd687691a4d6c2ab8c82f8023f6e7f1e504355 (patch)
tree5d2928289aaa842770492951cb28f3b677f61a86
parent71c8da65b7750ed851facae85a1ced4dccb02075 (diff)
downloadmongo-4fbd687691a4d6c2ab8c82f8023f6e7f1e504355.tar.gz
SERVER-63867 Allow zero plan cache maximum size
(cherry picked from commit 6f38fe9484d8ac4814416962a7584e5e5353ed76)
-rw-r--r--src/mongo/db/query/plan_cache.h3
-rw-r--r--src/mongo/db/query/plan_cache_test.cpp14
2 files changed, 15 insertions, 2 deletions
diff --git a/src/mongo/db/query/plan_cache.h b/src/mongo/db/query/plan_cache.h
index 889cd5dc1dd..5d92735f117 100644
--- a/src/mongo/db/query/plan_cache.h
+++ b/src/mongo/db/query/plan_cache.h
@@ -282,8 +282,7 @@ public:
explicit PlanCacheBase(size_t cacheSize, size_t numPartitions = 1)
: _numPartitions(numPartitions) {
invariant(numPartitions > 0);
- invariant(cacheSize / numPartitions > 0);
- auto lru = Lru(cacheSize / numPartitions);
+ Lru lru{cacheSize / numPartitions};
_partitionedCache = std::make_unique<Partitioned<Lru, Partitioner>>(numPartitions, lru);
}
diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp
index 72efd3f6e67..5e0bfc55806 100644
--- a/src/mongo/db/query/plan_cache_test.cpp
+++ b/src/mongo/db/query/plan_cache_test.cpp
@@ -2080,4 +2080,18 @@ TEST(PlanCacheTest, PlanCacheSizeWithMultiplePlanCaches) {
ASSERT_EQ(planCacheTotalSizeEstimateBytes.get(), originalSize);
}
+TEST(PlanCacheTest, PlanCacheMaxSizeParameterCanBeZero) {
+ PlanCache planCache{0U};
+ unique_ptr<CanonicalQuery> query(canonicalize("{a: 1, c: 1}"));
+ auto qs = getQuerySolutionForCaching();
+ auto decision = createDecision(1U);
+ auto decisionPtr = decision.get();
+
+ ASSERT_OK(planCache.set(makeKey(*query),
+ qs->cacheData->clone(),
+ *decisionPtr,
+ Date_t{},
+ plan_cache_util::buildDebugInfo(*query, std::move(decision))));
+ ASSERT_EQ(0U, planCache.size());
+}
} // namespace