summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_lookup.cpp
diff options
context:
space:
mode:
authorBenjamin Murphy <benjamin_murphy@me.com>2016-02-10 17:24:21 -0500
committerBenjamin Murphy <benjamin_murphy@me.com>2016-03-24 11:05:32 -0400
commitf4bbde02bab191cdba4195ec9ad73c60d4aece41 (patch)
treece812891454e6d5ed946813452685f7590b8efbf /src/mongo/db/pipeline/document_source_lookup.cpp
parentf40294818ce8690f1a485ca32ea52e33e137b7ea (diff)
downloadmongo-f4bbde02bab191cdba4195ec9ad73c60d4aece41.tar.gz
SERVER-4507 Group stages now take advantage of sorted input sequences.
Diffstat (limited to 'src/mongo/db/pipeline/document_source_lookup.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp
index f9927de1e6f..4e63247bef4 100644
--- a/src/mongo/db/pipeline/document_source_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup.cpp
@@ -128,6 +128,32 @@ BSONObj DocumentSourceLookUp::queryForInput(const Document& input) const {
return query.obj();
}
+BSONObjSet DocumentSourceLookUp::getOutputSorts() {
+ BSONObjSet out;
+
+ BSONObjSet inputSort = pSource->getOutputSorts();
+ std::string asPath = _as.getPath(false);
+
+ for (auto&& sortObj : inputSort) {
+ // Truncate each sortObj at the '_as' path.
+ BSONObjBuilder outputSort;
+
+ for (BSONElement fieldSort : sortObj) {
+ if (fieldSort.fieldNameStringData() == asPath) {
+ break;
+ }
+ outputSort.append(fieldSort);
+ }
+
+ BSONObj outSortObj = outputSort.obj();
+ if (!outSortObj.isEmpty()) {
+ out.insert(outSortObj);
+ }
+ }
+
+ return out;
+}
+
boost::optional<Document> DocumentSourceLookUp::unwindResult() {
const boost::optional<FieldPath> indexPath(_unwindSrc->indexPath());