summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorDavid Storch <david.storch@mongodb.com>2022-05-03 23:17:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-04 00:08:29 +0000
commitf462237ac17a9c8a3e4a5a3fb6bbe6a966d4be85 (patch)
tree6e37a46ffd65e3a18c300bfe8672909a7b43fcb6 /src/mongo/db/query
parentc9260ac7135fc183f2a785124d033debc63e2734 (diff)
downloadmongo-f462237ac17a9c8a3e4a5a3fb6bbe6a966d4be85.tar.gz
SERVER-64315 Re-enable caching of SBE plans when there is a single query solution
This reverts commit f8589f840c8fee60abc482d2d2c41979e356922a.
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/classic_plan_cache.cpp10
-rw-r--r--src/mongo/db/query/get_executor.cpp9
-rw-r--r--src/mongo/db/query/sbe_sub_planner.cpp3
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 f69ee7e93d0..aa5ac8cc6b6 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -1342,11 +1342,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{