diff options
author | Haley Connelly <haley.connelly@10gen.com> | 2018-08-02 17:18:32 -0400 |
---|---|---|
committer | Haley Connelly <haley.connelly@10gen.com> | 2018-08-02 17:18:38 -0400 |
commit | ba50688792f3f038271af9edb3d0207691f6f63b (patch) | |
tree | aedb8f9caf4c12852426ff332324de81c33d154f /src/mongo/db/commands | |
parent | e68e228f0ebc6c70b808c173cedbda2b7dcfc87c (diff) | |
download | mongo-ba50688792f3f038271af9edb3d0207691f6f63b.tar.gz |
SERVER-35981 Include hash of plan cache key in planCacheListShapes and planCacheListPlans
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/index_filter_commands_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/commands/plan_cache_commands.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/commands/plan_cache_commands_test.cpp | 27 |
3 files changed, 24 insertions, 23 deletions
diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp index f9c6fb51f70..ffc0419616d 100644 --- a/src/mongo/db/commands/index_filter_commands_test.cpp +++ b/src/mongo/db/commands/index_filter_commands_test.cpp @@ -167,13 +167,11 @@ bool planCacheContains(OperationContext* opCtx, unique_ptr<CanonicalQuery> inputQuery = std::move(statusWithInputQuery.getValue()); // Retrieve cache entries from plan cache. - vector<PlanCacheEntry*> entries = planCache.getAllEntries(); + auto entries = planCache.getAllEntries(); // Search keys. bool found = false; - for (vector<PlanCacheEntry*>::const_iterator i = entries.begin(); i != entries.end(); i++) { - PlanCacheEntry* entry = *i; - + for (auto&& entry : entries) { // Canonicalizing query shape in cache entry to get cache key. // Alternatively, we could add key to PlanCacheEntry but that would be used in one place // only. @@ -189,8 +187,6 @@ bool planCacheContains(OperationContext* opCtx, if (planCache.computeKey(*currentQuery) == planCache.computeKey(*inputQuery)) { found = true; } - // Release resources for cache entry after extracting key. - delete entry; } return found; } diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp index 9237700b70b..1210588d066 100644 --- a/src/mongo/db/commands/plan_cache_commands.cpp +++ b/src/mongo/db/commands/plan_cache_commands.cpp @@ -46,6 +46,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/query/explain.h" #include "mongo/db/query/plan_ranker.h" +#include "mongo/util/hex.h" #include "mongo/util/log.h" namespace { @@ -246,11 +247,10 @@ Status PlanCacheListQueryShapes::list(const PlanCache& planCache, BSONObjBuilder invariant(bob); // Fetch all cached solutions from plan cache. - vector<PlanCacheEntry*> solutions = planCache.getAllEntries(); + auto entries = planCache.getAllEntries(); BSONArrayBuilder arrayBuilder(bob->subarrayStart("shapes")); - for (vector<PlanCacheEntry*>::const_iterator i = solutions.begin(); i != solutions.end(); i++) { - PlanCacheEntry* entry = *i; + for (auto&& entry : entries) { invariant(entry); BSONObjBuilder shapeBuilder(arrayBuilder.subobjStart()); @@ -260,10 +260,8 @@ Status PlanCacheListQueryShapes::list(const PlanCache& planCache, BSONObjBuilder if (!entry->collation.isEmpty()) { shapeBuilder.append("collation", entry->collation); } + shapeBuilder.append("queryHash", unsignedIntToFixedLengthHex(entry->queryHash)); shapeBuilder.doneFast(); - - // Release resources for cached solution after extracting query shape. - delete entry; } arrayBuilder.doneFast(); @@ -440,7 +438,7 @@ Status PlanCacheListPlans::list(OperationContext* opCtx, // Append the time the entry was inserted into the plan cache. bob->append("timeOfCreation", entry->timeOfCreation); - + bob->append("queryHash", unsignedIntToFixedLengthHex(entry->queryHash)); // Append whether or not the entry is active. bob->append("isActive", entry->isActive); bob->append("works", static_cast<long long>(entry->works)); diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp index 89f0cc8b0f0..a540d9c68db 100644 --- a/src/mongo/db/commands/plan_cache_commands_test.cpp +++ b/src/mongo/db/commands/plan_cache_commands_test.cpp @@ -348,11 +348,13 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) { << cqB->getQueryRequest().getProj()); ASSERT_TRUE( std::find_if(shapesBefore.begin(), shapesBefore.end(), [&shapeA](const BSONObj& obj) { - return SimpleBSONObjComparator::kInstance.evaluate(shapeA == obj); + auto filteredObj = obj.removeField("queryHash"); + return SimpleBSONObjComparator::kInstance.evaluate(shapeA == filteredObj); }) != shapesBefore.end()); ASSERT_TRUE( std::find_if(shapesBefore.begin(), shapesBefore.end(), [&shapeB](const BSONObj& obj) { - return SimpleBSONObjComparator::kInstance.evaluate(shapeB == obj); + auto filteredObj = obj.removeField("queryHash"); + return SimpleBSONObjComparator::kInstance.evaluate(shapeB == filteredObj); }) != shapesBefore.end()); // Drop {b: 1} from cache. Make sure {a: 1} is still in cache afterwards. @@ -362,7 +364,8 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) { opCtx.get(), &planCache, nss.ns(), BSON("query" << cqB->getQueryObj()))); vector<BSONObj> shapesAfter = getShapes(planCache); ASSERT_EQUALS(shapesAfter.size(), 1U); - ASSERT_BSONOBJ_EQ(shapesAfter[0], shapeA); + auto filteredShape0 = shapesAfter[0].removeField("queryHash"); + ASSERT_BSONOBJ_EQ(filteredShape0, shapeA); } TEST(PlanCacheCommandsTest, planCacheClearOneKeyCollation) { @@ -414,13 +417,16 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKeyCollation) { << cqCollation->getCollator()->getSpec().toBSON()); ASSERT_TRUE( std::find_if(shapesBefore.begin(), shapesBefore.end(), [&shape](const BSONObj& obj) { - return SimpleBSONObjComparator::kInstance.evaluate(shape == obj); + auto filteredObj = obj.removeField("queryHash"); + return SimpleBSONObjComparator::kInstance.evaluate(shape == filteredObj); }) != shapesBefore.end()); - ASSERT_TRUE( - std::find_if( - shapesBefore.begin(), shapesBefore.end(), [&shapeWithCollation](const BSONObj& obj) { - return SimpleBSONObjComparator::kInstance.evaluate(shapeWithCollation == obj); - }) != shapesBefore.end()); + ASSERT_TRUE(std::find_if(shapesBefore.begin(), + shapesBefore.end(), + [&shapeWithCollation](const BSONObj& obj) { + auto filteredObj = obj.removeField("queryHash"); + return SimpleBSONObjComparator::kInstance.evaluate( + shapeWithCollation == filteredObj); + }) != shapesBefore.end()); // Drop query with collation from cache. Make other query is still in cache afterwards. BSONObjBuilder bob; @@ -428,7 +434,8 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKeyCollation) { ASSERT_OK(PlanCacheClear::clear(opCtx.get(), &planCache, nss.ns(), shapeWithCollation)); vector<BSONObj> shapesAfter = getShapes(planCache); ASSERT_EQUALS(shapesAfter.size(), 1U); - ASSERT_BSONOBJ_EQ(shapesAfter[0], shape); + auto filteredShape0 = shapesAfter[0].removeField("queryHash"); + ASSERT_BSONOBJ_EQ(filteredShape0, shape); } /** |