diff options
author | Anton Korshunov <anton.korshunov@mongodb.com> | 2022-04-05 09:24:57 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-05 09:52:43 +0000 |
commit | 33720b4cbb38b4dc5ab98f9bde68a62451e93745 (patch) | |
tree | b2c1afc3bca9d377b5be012d3b64de38b66b78fb | |
parent | 4146e4cc549504cf3e4909b7ab9f63215947cbcd (diff) | |
download | mongo-33720b4cbb38b4dc5ab98f9bde68a62451e93745.tar.gz |
SERVER-64976 Caching of sub-pipelines should be allowed with explain
-rw-r--r-- | src/mongo/db/query/classic_plan_cache.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/mongo/db/query/classic_plan_cache.cpp b/src/mongo/db/query/classic_plan_cache.cpp index aa3f150291c..31ac6d13550 100644 --- a/src/mongo/db/query/classic_plan_cache.cpp +++ b/src/mongo/db/query/classic_plan_cache.cpp @@ -149,7 +149,13 @@ bool shouldCacheQuery(const CanonicalQuery& query) { // We don't read or write from the plan cache for explain. This ensures that explain queries // don't affect cache state, and it also makes sure that we can always generate information // regarding rejected plans and/or trial period execution of candidate plans. - if (query.getExplain()) { + // + // In order to be able to correctly measure 'executionTimeMillis' stats we should only skip + // caching top-level plans. Otherwise, if we were to skip caching inner pipelines for $lookup + // queries, we could run through the multi-planner for each document coming from the outer side, + // completely skewing the 'executionTimeMillis' stats. + tassert(6497600, "expCtx is null", query.getExpCtxRaw()); + if (query.getExplain() && query.getExpCtxRaw()->subPipelineDepth == 0) { return false; } |