diff options
author | David Storch <david.storch@mongodb.com> | 2022-05-03 23:17:45 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-04 18:11:43 +0000 |
commit | a616699c511fb395f3c0c6f53e705b306927a687 (patch) | |
tree | cc6a204210c02c149505bd5f744b1b4433135300 /src/mongo/db/query | |
parent | 3c0df34e8a6a4c8f68428c2fbfb965f0b2e42e64 (diff) | |
download | mongo-a616699c511fb395f3c0c6f53e705b306927a687.tar.gz |
SERVER-64315 Re-enable caching of SBE plans when there is a single query solution
This reverts commit f8589f840c8fee60abc482d2d2c41979e356922a.
(cherry picked from commit f462237ac17a9c8a3e4a5a3fb6bbe6a966d4be85)
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r-- | src/mongo/db/query/classic_plan_cache.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/query/get_executor.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/query/sbe_sub_planner.cpp | 3 |
3 files changed, 10 insertions, 12 deletions
diff --git a/src/mongo/db/query/classic_plan_cache.cpp b/src/mongo/db/query/classic_plan_cache.cpp index 31ac6d13550..5f33481fef6 100644 --- a/src/mongo/db/query/classic_plan_cache.cpp +++ b/src/mongo/db/query/classic_plan_cache.cpp @@ -150,12 +150,12 @@ bool shouldCacheQuery(const CanonicalQuery& query) { // 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. // - // 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. + // There is one exception: $lookup's implementation in the DocumentSource engine relies on + // caching the plan on the inner side in order to avoid repeating the planning process for every + // document on the outer side. To ensure that the 'executionTimeMillis' value is accurate for + // $lookup, we allow the inner side to use the cache even if the query is an explain. tassert(6497600, "expCtx is null", query.getExpCtxRaw()); - if (query.getExplain() && query.getExpCtxRaw()->subPipelineDepth == 0) { + if (query.getExplain() && !query.getExpCtxRaw()->inLookup) { return false; } diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index 3ea135da726..07b2e440e64 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -1343,11 +1343,10 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getSlotBasedExe roots[0] = helper.buildExecutableTree(*(solutions[0])); } auto&& [root, data] = roots[0]; - // TODO SERVER-64315: re-enable caching of single solution plans - // if (!planningResult->recoveredPinnedCacheEntry()) { - // plan_cache_util::updatePlanCache( - // opCtx, collections.getMainCollection(), *cq, *solutions[0], *root, data); - // } + if (!planningResult->recoveredPinnedCacheEntry()) { + plan_cache_util::updatePlanCache( + opCtx, collections.getMainCollection(), *cq, *solutions[0], *root, data); + } // Prepare the SBE tree for execution. stage_builder::prepareSlotBasedExecutableTree( diff --git a/src/mongo/db/query/sbe_sub_planner.cpp b/src/mongo/db/query/sbe_sub_planner.cpp index 377c65d2d3e..e5e714ad3aa 100644 --- a/src/mongo/db/query/sbe_sub_planner.cpp +++ b/src/mongo/db/query/sbe_sub_planner.cpp @@ -117,8 +117,7 @@ CandidatePlans SubPlanner::plan( // TODO SERVER-61507: do it unconditionally when $group pushdown is integrated with the SBE plan // cache. if (_cq.pipeline().empty()) { - // TODO SERVER-64315: re-enable caching of single solution plans - // plan_cache_util::updatePlanCache(_opCtx, mainColl, _cq, *compositeSolution, *root, data); + plan_cache_util::updatePlanCache(_opCtx, mainColl, _cq, *compositeSolution, *root, data); } return {makeVector(plan_ranker::CandidatePlan{ |