summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/pipeline.cpp
diff options
context:
space:
mode:
authorBen Shteinfeld <ben.shteinfeld@mongodb.com>2023-04-05 15:01:11 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-05 19:35:13 +0000
commit94ac53cc26b9dd35aa91ecd34c8f0e440f4ae70c (patch)
tree071fb52139bc626b2773353c51e3d347f7cde25d /src/mongo/db/pipeline/pipeline.cpp
parent714f743f438bb7ded54a4c8693ba9ccf85954dfb (diff)
downloadmongo-94ac53cc26b9dd35aa91ecd34c8f0e440f4ae70c.tar.gz
SERVER-75670 Avoid marking excluded fields in projection as 'generated' during pipeline dependency analysis.
Diffstat (limited to 'src/mongo/db/pipeline/pipeline.cpp')
-rw-r--r--src/mongo/db/pipeline/pipeline.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp
index 36f74c1ca8f..db9f6923c4e 100644
--- a/src/mongo/db/pipeline/pipeline.cpp
+++ b/src/mongo/db/pipeline/pipeline.cpp
@@ -34,6 +34,7 @@
#include <algorithm>
#include "mongo/base/error_codes.h"
+#include "mongo/base/exact_cast.h"
#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/exec/document_value/document.h"
#include "mongo/db/jsobj.h"
@@ -44,6 +45,7 @@
#include "mongo/db/pipeline/document_source_match.h"
#include "mongo/db/pipeline/document_source_merge.h"
#include "mongo/db/pipeline/document_source_out.h"
+#include "mongo/db/pipeline/document_source_single_document_transformation.h"
#include "mongo/db/pipeline/expression_context.h"
#include "mongo/db/pipeline/lite_parsed_pipeline.h"
#include "mongo/db/pipeline/search_helper.h"
@@ -678,8 +680,18 @@ DepsTracker Pipeline::getDependenciesForContainer(
knowAllFields = status & DepsTracker::State::EXHAUSTIVE_FIELDS;
// Check if this stage modifies any fields that we should track for use by later stages.
+ // Fields which are part of exclusion projections should not be marked as generated,
+ // despite them being modified.
auto localGeneratedPaths = source->getModifiedPaths();
- if (localGeneratedPaths.type == DocumentSource::GetModPathsReturn::Type::kFiniteSet) {
+ auto isExclusionProjection = [&]() {
+ const auto projStage =
+ exact_pointer_cast<DocumentSourceSingleDocumentTransformation*>(source.get());
+ return projStage &&
+ projStage->getType() ==
+ TransformerInterface::TransformerType::kExclusionProjection;
+ };
+ if (localGeneratedPaths.type == DocumentSource::GetModPathsReturn::Type::kFiniteSet &&
+ !isExclusionProjection()) {
auto newPathNames = localGeneratedPaths.getNewNames();
generatedPaths.insert(newPathNames.begin(), newPathNames.end());
}