diff options
author | Mickey. J Winters <mickey.winters@mongodb.com> | 2021-10-06 01:22:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-06 01:46:56 +0000 |
commit | 921bbff41b2132af13e45b2a7879f3fc4fef324b (patch) | |
tree | f5a20934385aa72faf22db398102886294423623 | |
parent | 08a1d17ecceb1a7e0ea969c61f1e0f11d672e6c2 (diff) | |
download | mongo-921bbff41b2132af13e45b2a7879f3fc4fef324b.tar.gz |
SERVER-60218 add initialize helper function for document_source_group
-rw-r--r-- | src/mongo/db/pipeline/document_source_group.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_group.h | 6 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp index 2ab40378383..73f3a76d81d 100644 --- a/src/mongo/db/pipeline/document_source_group.cpp +++ b/src/mongo/db/pipeline/document_source_group.cpp @@ -549,11 +549,16 @@ private: } // namespace DocumentSource::GetNextResult DocumentSourceGroup::initialize() { - const size_t numAccumulators = _accumulatedFields.size(); - - // Barring any pausing, this loop exhausts 'pSource' and populates '_groups'. GetNextResult input = pSource->getNext(); + return initializeSelf(input); +} +// This separate NOINLINE function is used here to decrease stack utilization of initialize() and +// prevent stack overflows. +MONGO_COMPILER_NOINLINE DocumentSource::GetNextResult DocumentSourceGroup::initializeSelf( + GetNextResult input) { + const size_t numAccumulators = _accumulatedFields.size(); + // Barring any pausing, this loop exhausts 'pSource' and populates '_groups'. for (; input.isAdvanced(); input = pSource->getNext()) { if (shouldSpillWithAttemptToSaveMemory()) { _sortedFiles.push_back(spill()); diff --git a/src/mongo/db/pipeline/document_source_group.h b/src/mongo/db/pipeline/document_source_group.h index 1e2e1c1d3d4..c9f635af90e 100644 --- a/src/mongo/db/pipeline/document_source_group.h +++ b/src/mongo/db/pipeline/document_source_group.h @@ -223,6 +223,12 @@ private: GetNextResult initialize(); /** + * Initializes this $group after any children are potentially initialized see initialize() for + * more details. + */ + GetNextResult initializeSelf(GetNextResult input); + + /** * Spill groups map to disk and returns an iterator to the file. Note: Since a sorted $group * does not exhaust the previous stage before returning, and thus does not maintain as large a * store of documents at any one time, only an unsorted group can spill to disk. |