diff options
author | Hana Pearlman <hana.pearlman@mongodb.com> | 2021-01-22 22:18:16 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-25 14:42:49 +0000 |
commit | dc70bfe933ba9f4b01a028eab72e44e2681fa09a (patch) | |
tree | bccf317c8495dd3bd7edbc9364b0b02f8d1d56c8 /src/mongo/db/pipeline/pipeline.cpp | |
parent | 62c3f69e2b2d2e805bb609edce01736f8ffa389b (diff) | |
download | mongo-dc70bfe933ba9f4b01a028eab72e44e2681fa09a.tar.gz |
SERVER-53487: Add utilized fields in an inclusion projection based on dependency analysis of pipeline after $unpackBucket
Diffstat (limited to 'src/mongo/db/pipeline/pipeline.cpp')
-rw-r--r-- | src/mongo/db/pipeline/pipeline.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp index 33f4cfc7dac..b54b76ab0a8 100644 --- a/src/mongo/db/pipeline/pipeline.cpp +++ b/src/mongo/db/pipeline/pipeline.cpp @@ -484,12 +484,23 @@ void Pipeline::addFinalSource(intrusive_ptr<DocumentSource> source) { _sources.push_back(source); } -DepsTracker Pipeline::getDependencies(QueryMetadataBitSet unavailableMetadata) const { - DepsTracker deps(unavailableMetadata); +DepsTracker Pipeline::getDependencies( + boost::optional<QueryMetadataBitSet> unavailableMetadata) const { + return getDependenciesForContainer(getContext(), _sources, unavailableMetadata); +} + +DepsTracker Pipeline::getDependenciesForContainer( + const boost::intrusive_ptr<ExpressionContext>& expCtx, + const SourceContainer& container, + boost::optional<QueryMetadataBitSet> unavailableMetadata) { + // If 'unavailableMetadata' was not specified, we assume all metadata is available. This allows + // us to call 'deps.setNeedsMetadata()' without throwing. + DepsTracker deps(unavailableMetadata.get_value_or(DepsTracker::kNoMetadata)); + bool hasUnsupportedStage = false; bool knowAllFields = false; bool knowAllMeta = false; - for (auto&& source : _sources) { + for (auto&& source : container) { DepsTracker localDeps(deps.getUnavailableMetadata()); DepsTracker::State status = source->getDependencies(&localDeps); @@ -521,11 +532,11 @@ DepsTracker Pipeline::getDependencies(QueryMetadataBitSet unavailableMetadata) c if (!knowAllFields) deps.needWholeDocument = true; // don't know all fields we need - if (!unavailableMetadata[DocumentMetadataFields::kTextScore]) { + if (!deps.getUnavailableMetadata()[DocumentMetadataFields::kTextScore]) { // There is a text score available. If we are the first half of a split pipeline, then we // have to assume future stages might depend on the textScore (unless we've encountered a // stage that doesn't preserve metadata). - if (getContext()->needsMerge && !knowAllMeta) { + if (expCtx->needsMerge && !knowAllMeta) { deps.setNeedsMetadata(DocumentMetadataFields::kTextScore, true); } } else { |