summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/explain.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2018-08-08 12:15:48 -0400
committerDavid Storch <david.storch@10gen.com>2018-08-09 15:54:07 -0400
commit25033952fa8cd51f18acada50f1894c232b610ff (patch)
tree877b7c82d7a5f1bf9dfb98397e1e39c6080d0bec /src/mongo/db/query/explain.cpp
parent8c2cd4720c59dae92c2b284efaec0f88a08b797a (diff)
downloadmongo-25033952fa8cd51f18acada50f1894c232b610ff.tar.gz
SERVER-36527 Add 'queryHash' to 'queryPlanner' explain output.
Diffstat (limited to 'src/mongo/db/query/explain.cpp')
-rw-r--r--src/mongo/db/query/explain.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp
index daefe9c3aea..14bb6154141 100644
--- a/src/mongo/db/query/explain.cpp
+++ b/src/mongo/db/query/explain.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/query/stage_builder.h"
#include "mongo/db/server_options.h"
#include "mongo/db/server_parameters.h"
+#include "mongo/util/hex.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/version.h"
@@ -649,11 +650,13 @@ void Explain::generatePlannerInfo(PlanExecutor* exec,
// Find whether there is an index filter set for the query shape. The 'indexFilterSet'
// field will always be false in the case of EOF or idhack plans.
bool indexFilterSet = false;
+ boost::optional<uint32_t> queryHash;
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)) {
// Found an index filter set on the query shape.
indexFilterSet = true;
@@ -674,6 +677,10 @@ void Explain::generatePlannerInfo(PlanExecutor* exec,
}
}
+ if (queryHash) {
+ plannerBob.append("queryHash", unsignedIntToFixedLengthHex(*queryHash));
+ }
+
BSONObjBuilder winningPlanBob(plannerBob.subobjStart("winningPlan"));
const auto winnerStats = getWinningPlanStatsTree(exec);
statsToBSON(*winnerStats.get(), &winningPlanBob, ExplainOptions::Verbosity::kQueryPlanner);