diff options
author | Ian Boros <ian.boros@10gen.com> | 2018-10-09 12:22:08 -0400 |
---|---|---|
committer | Ian Boros <ian.boros@10gen.com> | 2018-11-06 17:45:50 -0500 |
commit | 50630d5c4ea5f731bdfd95b2dab5ab4e9620fd10 (patch) | |
tree | c5ff2b837dd7c6de8ccd606434363ad4454b0e3a /src/mongo/db/query/explain.cpp | |
parent | 5738e29558432727846902dde7fd257aee36deec (diff) | |
download | mongo-50630d5c4ea5f731bdfd95b2dab5ab4e9620fd10.tar.gz |
SERVER-33303 Add stable plan cache key and use for index filters
Diffstat (limited to 'src/mongo/db/query/explain.cpp')
-rw-r--r-- | src/mongo/db/query/explain.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp index 95b07d91c68..92586ac1c47 100644 --- a/src/mongo/db/query/explain.cpp +++ b/src/mongo/db/query/explain.cpp @@ -45,6 +45,7 @@ #include "mongo/db/exec/text.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/keypattern.h" +#include "mongo/db/query/canonical_query_encoder.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/plan_executor.h" #include "mongo/db/query/plan_summary_stats.h" @@ -645,13 +646,17 @@ void Explain::generatePlannerInfo(PlanExecutor* exec, // field will always be false in the case of EOF or idhack plans. bool indexFilterSet = false; boost::optional<uint32_t> queryHash; + boost::optional<uint32_t> planCacheKeyHash; if (collection && exec->getCanonicalQuery()) { const CollectionInfoCache* infoCache = collection->infoCache(); const QuerySettings* querySettings = infoCache->getQuerySettings(); PlanCacheKey planCacheKey = infoCache->getPlanCache()->computeKey(*exec->getCanonicalQuery()); - queryHash = PlanCache::computeQueryHash(planCacheKey); - if (auto allowedIndicesFilter = querySettings->getAllowedIndicesFilter(planCacheKey)) { + planCacheKeyHash = canonical_query_encoder::computeHash(planCacheKey.toString()); + queryHash = canonical_query_encoder::computeHash(planCacheKey.getStableKeyStringData()); + + if (auto allowedIndicesFilter = + querySettings->getAllowedIndicesFilter(planCacheKey.getStableKey())) { // Found an index filter set on the query shape. indexFilterSet = true; } @@ -675,6 +680,10 @@ void Explain::generatePlannerInfo(PlanExecutor* exec, plannerBob.append("queryHash", unsignedIntToFixedLengthHex(*queryHash)); } + if (planCacheKeyHash) { + plannerBob.append("planCacheKey", unsignedIntToFixedLengthHex(*planCacheKeyHash)); + } + BSONObjBuilder winningPlanBob(plannerBob.subobjStart("winningPlan")); const auto winnerStats = getWinningPlanStatsTree(exec); statsToBSON(*winnerStats.get(), &winningPlanBob, ExplainOptions::Verbosity::kQueryPlanner); @@ -999,6 +1008,7 @@ void Explain::planCacheEntryToBSON(const PlanCacheEntry& entry, BSONObjBuilder* } shapeBuilder.doneFast(); out->append("queryHash", unsignedIntToFixedLengthHex(entry.queryHash)); + out->append("planCacheKey", unsignedIntToFixedLengthHex(entry.planCacheKey)); // Append whether or not the entry is active. out->append("isActive", entry.isActive); |