Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/mongo/db/pipeline/document_source_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ void DocumentSourceSort::serializeToArray(
<< "mergePresorted"
<< (_mergingPresorted ? Value(true) : Value())
<< "limit"
<< (limitSrc ? Value(limitSrc->getLimit()) : Value())))));
<< (_limitSrc ? Value(_limitSrc->getLimit()) : Value())))));
} else { // one Value for $sort and maybe a Value for $limit
MutableDocument inner(sortKeyPattern(SortKeySerialization::kForPipelineSerialization));
if (_mergingPresorted) {
inner["$mergePresorted"] = Value(true);
}
array.push_back(Value(DOC(kStageName << inner.freeze())));

if (limitSrc) {
limitSrc->serializeToArray(array);
if (_limitSrc) {
_limitSrc->serializeToArray(array);
}
}
}
Expand All @@ -155,7 +155,7 @@ void DocumentSourceSort::doDispose() {
}

long long DocumentSourceSort::getLimit() const {
return limitSrc ? limitSrc->getLimit() : -1;
return _limitSrc ? _limitSrc->getLimit() : -1;
}

Document DocumentSourceSort::sortKeyPattern(SortKeySerialization serializationMode) const {
Expand Down Expand Up @@ -319,8 +319,8 @@ SortOptions DocumentSourceSort::makeSortOptions() const {
verify(_sortPattern.size());

SortOptions opts;
if (limitSrc)
opts.limit = limitSrc->getLimit();
if (_limitSrc)
opts.limit = _limitSrc->getLimit();

opts.maxMemoryUsageBytes = _maxMemoryUsageBytes;
if (pExpCtx->allowDiskUse && !pExpCtx->inMongos) {
Expand Down Expand Up @@ -529,7 +529,7 @@ std::list<intrusive_ptr<DocumentSource>> DocumentSourceSort::getMergeSources() {
other->sortKeyPattern(SortKeySerialization::kForPipelineSerialization).toBson(),
pExpCtx->getCollator()};
other->_paths = _paths;
other->limitSrc = limitSrc;
other->_limitSrc = _limitSrc;
other->_maxMemoryUsageBytes = _maxMemoryUsageBytes;
other->_mergingPresorted = true;
other->_rawSort = _rawSort;
Expand Down
10 changes: 5 additions & 5 deletions src/mongo/db/pipeline/document_source_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DocumentSourceSort final : public DocumentSource, public SplittableDocumen
: ChangeStreamRequirement::kBlacklist);

// Can't swap with a $match if a limit has been absorbed, as $match can't swap with $limit.
constraints.canSwapWithMatch = !limitSrc;
constraints.canSwapWithMatch = !_limitSrc;
return constraints;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ class DocumentSourceSort final : public DocumentSource, public SplittableDocumen
};

boost::intrusive_ptr<DocumentSourceLimit> getLimitSrc() const {
return limitSrc;
return _limitSrc;
}

protected:
Expand Down Expand Up @@ -242,8 +242,8 @@ class DocumentSourceSort final : public DocumentSource, public SplittableDocumen
* the smallest limit.
*/
void setLimitSrc(boost::intrusive_ptr<DocumentSourceLimit> limit) {
if (!limitSrc || limit->getLimit() < limitSrc->getLimit()) {
limitSrc = limit;
if (!_limitSrc || limit->getLimit() < _limitSrc->getLimit()) {
_limitSrc = limit;
}
}

Expand All @@ -258,7 +258,7 @@ class DocumentSourceSort final : public DocumentSource, public SplittableDocumen
// The set of paths on which we're sorting.
std::set<std::string> _paths;

boost::intrusive_ptr<DocumentSourceLimit> limitSrc;
boost::intrusive_ptr<DocumentSourceLimit> _limitSrc;

uint64_t _maxMemoryUsageBytes;
bool _done;
Expand Down