summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/pipeline_d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/pipeline_d.cpp')
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp
index 932b3e4f3e4..09bd1b1653f 100644
--- a/src/mongo/db/pipeline/pipeline_d.cpp
+++ b/src/mongo/db/pipeline/pipeline_d.cpp
@@ -257,6 +257,9 @@ public:
!bool(css->getMetadata()));
PipelineD::prepareCursorSource(autoColl->getCollection(), expCtx->ns, nullptr, pipeline);
+ // Optimize again, since there may be additional optimizations that can be done after adding
+ // the initial cursor stage.
+ pipeline->optimizePipeline();
return Status::OK();
}
@@ -860,11 +863,7 @@ void PipelineD::addCursorSource(Collection* collection,
pSource->setProjection(deps.toProjection(), deps.toParsedDeps());
}
-
- // Add the initial DocumentSourceCursor to the front of the pipeline. Then optimize again in
- // case the new stage can be absorbed with the first stages of the pipeline.
pipeline->addInitialSource(pSource);
- pipeline->optimizePipeline();
}
Timestamp PipelineD::getLatestOplogTimestamp(const Pipeline* pipeline) {