summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/projection_node.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/exec/projection_node.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/exec/projection_node.cpp')
-rw-r--r--src/mongo/db/exec/projection_node.cpp42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/mongo/db/exec/projection_node.cpp b/src/mongo/db/exec/projection_node.cpp
index 6b053c4593f..1ef569ecd75 100644
--- a/src/mongo/db/exec/projection_node.cpp
+++ b/src/mongo/db/exec/projection_node.cpp
@@ -48,8 +48,7 @@ void ProjectionNode::addProjectionForPath(const FieldPath& path) {
void ProjectionNode::_addProjectionForPath(const FieldPath& path) {
makeOptimizationsStale();
if (path.getPathLength() == 1) {
- auto it = _projectedFields.insert(_projectedFields.end(), path.fullPath());
- _projectedFieldsSet.insert(StringData(*it));
+ _projectedFields.insert(path.fullPath());
return;
}
// FieldPath can't be empty, so it is safe to obtain the first path component here.
@@ -139,18 +138,12 @@ void ProjectionNode::applyProjections(const Document& inputDoc, MutableDocument*
auto it = inputDoc.fieldIterator();
size_t projectedFields = 0;
- bool isIncl = isIncluded();
-
while (it.more()) {
auto fieldName = it.fieldName();
- if (_projectedFieldsSet.find(fieldName) != _projectedFieldsSet.end()) {
- if (isIncl) {
- outputProjectedField(fieldName, it.next().second, outputDoc);
- } else {
- outputProjectedField(fieldName, Value(), outputDoc);
- it.advance();
- }
+ if (_projectedFields.find(fieldName) != _projectedFields.end()) {
+ outputProjectedField(
+ fieldName, applyLeafProjectionToValue(it.next().second), outputDoc);
++projectedFields;
} else if (auto childIt = _children.find(fieldName); childIt != _children.end()) {
outputProjectedField(
@@ -236,7 +229,7 @@ Value ProjectionNode::applyExpressionsToValue(const Document& root, Value inputV
}
}
-void ProjectionNode::reportProjectedPaths(OrderedPathSet* projectedPaths) const {
+void ProjectionNode::reportProjectedPaths(std::set<std::string>* projectedPaths) const {
for (auto&& projectedField : _projectedFields) {
projectedPaths->insert(FieldPath::getFullyQualifiedPath(_pathToNode, projectedField));
}
@@ -246,7 +239,7 @@ void ProjectionNode::reportProjectedPaths(OrderedPathSet* projectedPaths) const
}
}
-void ProjectionNode::reportComputedPaths(OrderedPathSet* computedPaths,
+void ProjectionNode::reportComputedPaths(std::set<std::string>* computedPaths,
StringMap<std::string>* renamedPaths) const {
for (auto&& computedPair : _expressions) {
// The expression's path is the concatenation of the path to this node, plus the field name
@@ -275,27 +268,25 @@ void ProjectionNode::optimize() {
_maxFieldsToProject = maxFieldsToProject();
}
-Document ProjectionNode::serialize(boost::optional<ExplainOptions::Verbosity> explain,
- const SerializationOptions& options) const {
+Document ProjectionNode::serialize(boost::optional<ExplainOptions::Verbosity> explain) const {
MutableDocument outputDoc;
- serialize(explain, &outputDoc, options);
+ serialize(explain, &outputDoc);
return outputDoc.freeze();
}
void ProjectionNode::serialize(boost::optional<ExplainOptions::Verbosity> explain,
- MutableDocument* output,
- const SerializationOptions& options) const {
+ MutableDocument* output) const {
// Determine the boolean value for projected fields in the explain output.
- const bool projVal = isIncluded();
+ const bool projVal = !applyLeafProjectionToValue(Value(true)).missing();
// Always put "_id" first if it was projected (implicitly or explicitly).
- if (_projectedFieldsSet.find("_id") != _projectedFieldsSet.end()) {
- output->addField(options.serializeFieldPath("_id"), Value(projVal));
+ if (_projectedFields.find("_id") != _projectedFields.end()) {
+ output->addField("_id", Value(projVal));
}
for (auto&& projectedField : _projectedFields) {
if (projectedField != "_id") {
- output->addField(options.serializeFieldPathFromString(projectedField), Value(projVal));
+ output->addField(projectedField, Value(projVal));
}
}
@@ -303,14 +294,13 @@ void ProjectionNode::serialize(boost::optional<ExplainOptions::Verbosity> explai
auto childIt = _children.find(field);
if (childIt != _children.end()) {
MutableDocument subDoc;
- childIt->second->serialize(explain, &subDoc, options);
- output->addField(options.serializeFieldPathFromString(field), subDoc.freezeToValue());
+ childIt->second->serialize(explain, &subDoc);
+ output->addField(field, subDoc.freezeToValue());
} else {
invariant(_policies.computedFieldsPolicy == ComputedFieldsPolicy::kAllowComputedFields);
auto expressionIt = _expressions.find(field);
invariant(expressionIt != _expressions.end());
- output->addField(options.serializeFieldPathFromString(field),
- expressionIt->second->serialize(options));
+ output->addField(field, expressionIt->second->serialize(static_cast<bool>(explain)));
}
}
}