diff options
author | Svilen Mihaylov <svilen.mihaylov@mongodb.com> | 2021-04-29 12:13:28 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-29 20:00:52 +0000 |
commit | 979f4ee6a9b8128140e9b08bdb9b177b7c55b3f0 (patch) | |
tree | c42062f93621356484db866626cb68b69dede7e2 | |
parent | 0b829194446f350fe6a8752f651d4b6163e4f62e (diff) | |
download | mongo-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.cpp | 9 |
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 {}; |