summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvilen Mihaylov <svilen.mihaylov@mongodb.com>2021-04-29 12:13:28 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-29 20:00:52 +0000
commit979f4ee6a9b8128140e9b08bdb9b177b7c55b3f0 (patch)
treec42062f93621356484db866626cb68b69dede7e2
parent0b829194446f350fe6a8752f651d4b6163e4f62e (diff)
downloadmongo-979f4ee6a9b8128140e9b08bdb9b177b7c55b3f0.tar.gz
SERVER-56494: Fix handling of groupby min/max rewrite if unpackbucket is the first stage.
-rw-r--r--src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp b/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp
index 1006fcd2e42..877c88fad55 100644
--- a/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp
+++ b/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp
@@ -777,7 +777,14 @@ DocumentSourceInternalUnpackBucket::rewriteGroupByMinMax(Pipeline::SourceContain
// group.
container->erase(std::next(itr));
*itr = std::move(newGroup);
- return {true, std::prev(itr)};
+
+ if (itr == container->begin()) {
+ // Optimize group stage.
+ return {true, itr};
+ } else {
+ // Give chance of the previous stage to optimize against group stage.
+ return {true, std::prev(itr)};
+ }
}
return {};