summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/bucket_unpacker.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-18 17:02:53 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-18 17:02:53 -0300
commit959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch)
treeacc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/db/exec/bucket_unpacker.cpp
parent76588293975fc059cf076779e4283e6ffaf8afff (diff)
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/db/exec/bucket_unpacker.cpp')
-rw-r--r--src/mongo/db/exec/bucket_unpacker.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/mongo/db/exec/bucket_unpacker.cpp b/src/mongo/db/exec/bucket_unpacker.cpp
index db14d8b08cc..8bba2da9e4d 100644
--- a/src/mongo/db/exec/bucket_unpacker.cpp
+++ b/src/mongo/db/exec/bucket_unpacker.cpp
@@ -986,9 +986,9 @@ BSONObj BucketSpec::pushdownPredicate(
BSONObjBuilder result;
if (metaOnlyPredicate)
- metaOnlyPredicate->serialize(&result);
+ metaOnlyPredicate->serialize(&result, {});
if (bucketMetricPredicate)
- bucketMetricPredicate->serialize(&result);
+ bucketMetricPredicate->serialize(&result, {});
return result.obj();
}
@@ -1546,7 +1546,9 @@ BSONObj BucketUnpacker::getNextBson() {
// Add computed meta projections.
for (auto&& name : _spec.computedMetaProjFields()) {
- builder.appendAs(_computedMetaProjections[name], name);
+ if (_computedMetaProjections[name]) {
+ builder.appendAs(_computedMetaProjections[name], name);
+ }
}
return builder.obj();
@@ -1757,12 +1759,18 @@ void BucketUnpacker::eraseMetaFromFieldSetAndDetermineIncludeMeta() {
}
}
-void BucketUnpacker::eraseExcludedComputedMetaProjFields() {
- if (_spec.behavior() == BucketSpec::Behavior::kExclude) {
- for (const auto& field : _spec.fieldSet()) {
- _spec.eraseFromComputedMetaProjFields(field);
- }
- }
+void BucketUnpacker::eraseUnneededComputedMetaProjFields() {
+ // If this is an inclusion spec and the current computed field is not part of in the include
+ // fields, it means the computed field should not be available after the current unpack stage.
+ // Similarly, for exclusion spec, if the current computed field is part of the exclude fields,
+ // the computed fields should not be available after the current unpack stage. This can happen
+ // if there was a $project stage after a $addFields stage.
+ bool removeIfInFieldSet = _spec.behavior() == BucketSpec::Behavior::kExclude;
+ auto conditionToErase = [&](const std::string& computedField) {
+ bool inFieldSet = _spec.fieldSet().find(computedField) != _spec.fieldSet().end();
+ return inFieldSet == removeIfInFieldSet;
+ };
+ _spec.eraseIfPredTrueFromComputedMetaProjFields(conditionToErase);
}
void BucketUnpacker::setBucketSpec(BucketSpec&& bucketSpec) {
@@ -1770,7 +1778,7 @@ void BucketUnpacker::setBucketSpec(BucketSpec&& bucketSpec) {
eraseMetaFromFieldSetAndDetermineIncludeMeta();
determineIncludeTimeField();
- eraseExcludedComputedMetaProjFields();
+ eraseUnneededComputedMetaProjFields();
_includeMinTimeAsMetadata = _spec.includeMinTimeAsMetadata;
_includeMaxTimeAsMetadata = _spec.includeMaxTimeAsMetadata;