summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2019-12-19 22:07:36 +0000
committerevergreen <evergreen@mongodb.com>2019-12-19 22:07:36 +0000
commit62c9e0b7393e6c636724ab3abc5ab400583cb668 (patch)
tree6acc42bad8fdf5426a00a00b13022d8c05317c6a /src/mongo/db
parent4cd114fb943075fe87879d66bfc764ce75aa565b (diff)
downloadmongo-62c9e0b7393e6c636724ab3abc5ab400583cb668.tar.gz
SERVER-44828 Correct logic to re-compute dependencies
We do this after absorbing a $sort into query layer, but this optimization was accidentally thwarted by a recent bug fix. This patch restores this optimization. (cherry picked from commit 68d9027d26d469ab003bf81be95df6395d4dad19) (cherry picked from commit 8170a1a318e3c12f31fcfd6094b970b0e27b9211)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp
index e195b75c091..f0934fdbf99 100644
--- a/src/mongo/db/pipeline/pipeline_d.cpp
+++ b/src/mongo/db/pipeline/pipeline_d.cpp
@@ -697,6 +697,16 @@ void PipelineD::prepareCursorSource(Collection* collection,
&sortObj,
&projForQuery));
+ // There may be fewer dependencies now if the sort was covered.
+ if (!sortObj.isEmpty()) {
+ LOG(5) << "Agg: recomputing dependencies due to a covered sort: " << redact(sortObj)
+ << ". Current projection: " << redact(projForQuery)
+ << ". Current dependencies: " << redact(deps.toProjection());
+ deps = pipeline->getDependencies(DocumentSourceMatch::isTextQuery(queryObj)
+ ? DepsTracker::MetadataAvailable::kTextScore
+ : DepsTracker::MetadataAvailable::kNoMetadata);
+ }
+
if (!projForQuery.isEmpty() && !sources.empty()) {
// Check for redundant $project in query with the same specification as the inclusion
@@ -796,6 +806,7 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> PipelineD::prep
std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec;
if (swExecutorSortAndProj.isOK()) {
// Success! We have a non-blocking sort and a covered projection.
+ LOG(5) << "Agg: Have a non-blocking sort and covered projection";
exec = std::move(swExecutorSortAndProj.getValue());
} else if (swExecutorSortAndProj == ErrorCodes::QueryPlanKilled) {
return {ErrorCodes::OperationFailed,
@@ -804,6 +815,8 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> PipelineD::prep
<< swExecutorSortAndProj.getStatus().toString()};
} else {
// The query system couldn't cover the projection.
+ LOG(5) << "Agg: The query system found a non-blocking sort but couldn't cover the "
+ "projection";
*projectionObj = BSONObj();
exec = std::move(swExecutorSort.getValue());
}
@@ -826,6 +839,7 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> PipelineD::prep
// The query system can't provide a non-blocking sort.
*sortObj = BSONObj();
}
+ LOG(5) << "Agg: The query system couldn't cover the sort";
// Either there was no $sort stage, or the query system could not provide a non-blocking
// sort.
@@ -903,14 +917,9 @@ void PipelineD::addCursorSource(Collection* collection,
if (!projectionObj.isEmpty()) {
pSource->setProjection(projectionObj, boost::none);
+ LOG(5) << "Agg: Setting projection with no dependencies: " << redact(projectionObj);
} else {
- // There may be fewer dependencies now if the sort was covered.
- if (!sortObj.isEmpty()) {
- deps = pipeline->getDependencies(DocumentSourceMatch::isTextQuery(queryObj)
- ? DepsTracker::MetadataAvailable::kTextScore
- : DepsTracker::MetadataAvailable::kNoMetadata);
- }
-
+ LOG(5) << "Agg: Setting projection with dependencies: " << redact(deps.toProjection());
pSource->setProjection(deps.toProjection(), deps.toParsedDeps());
}
}