summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/explain.cpp
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2018-10-09 12:22:08 -0400
committerIan Boros <ian.boros@10gen.com>2018-11-06 11:24:25 -0500
commit36d4668e854d8bd17e8b684dbbf42b3b0903bbe7 (patch)
tree4815a0b5a9b712c5fb93f59e6a57d4cd6f0ae2f7 /src/mongo/db/query/explain.cpp
parenta090ee789498e709eef4c2d28bc1326070c1e67a (diff)
downloadmongo-36d4668e854d8bd17e8b684dbbf42b3b0903bbe7.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.cpp14
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);