summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
authorBenjamin Murphy <benjamin_murphy@me.com>2016-04-01 12:52:21 -0400
committerBenjamin Murphy <benjamin_murphy@me.com>2016-04-04 10:42:17 -0400
commitae3ee1ceddc8af4a123090f6819d082058f3ea94 (patch)
treedef542656b1a1bb94bf39fa9f2cc122924f6925c /src/mongo/db/pipeline
parenta253c2b42aa124df687b54982283270f33e29994 (diff)
downloadmongo-ae3ee1ceddc8af4a123090f6819d082058f3ea94.tar.gz
SERVER-23469 Match on unwind's indexPath is no longer optimized.
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r--src/mongo/db/pipeline/document_source_unwind.cpp9
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp13
2 files changed, 20 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_unwind.cpp b/src/mongo/db/pipeline/document_source_unwind.cpp
index 506627cc4dd..bba51298389 100644
--- a/src/mongo/db/pipeline/document_source_unwind.cpp
+++ b/src/mongo/db/pipeline/document_source_unwind.cpp
@@ -231,8 +231,13 @@ Pipeline::SourceContainer::iterator DocumentSourceUnwind::optimizeAt(
if (auto nextMatch = dynamic_cast<DocumentSourceMatch*>((*std::next(itr)).get())) {
const bool includeDollarPrefix = false;
- std::set<std::string> field = {_unwindPath.getPath(includeDollarPrefix)};
- auto splitMatch = nextMatch->splitSourceBy(field);
+ std::set<std::string> fields = {_unwindPath.getPath(includeDollarPrefix)};
+
+ if (_indexPath) {
+ fields.insert((*_indexPath).getPath(false));
+ }
+
+ auto splitMatch = nextMatch->splitSourceBy(fields);
invariant(splitMatch.first || splitMatch.second);
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index e5afb99fb86..1b583ccf70c 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -315,6 +315,18 @@ class MatchShouldNotOptimizeWithElemMatch : public Base {
}
};
+class MatchShouldNotOptimizeWhenMatchingOnIndexField : public Base {
+ string inputPipeJson() {
+ return "[{$unwind: {path: '$a', includeArrayIndex: 'foo'}}, "
+ " {$match: {foo: 0, b: 1}}]";
+ }
+ string outputPipeJson() {
+ return "[{$match: {b: {$eq: 1}}}, "
+ " {$unwind: {path: '$a', includeArrayIndex: 'foo'}}, "
+ " {$match: {foo: {$eq: 0}}}]";
+ }
+};
+
class MatchWithNorOnlySplitsIndependentChildren : public Base {
string inputPipeJson() {
return "[{$unwind: {path: '$a'}}, "
@@ -758,6 +770,7 @@ public:
add<Optimizations::Local::LookupShouldNotCoalesceWithUnwindNotOnAs>();
add<Optimizations::Local::MatchShouldDuplicateItselfBeforeRedact>();
add<Optimizations::Local::MatchShouldSwapWithUnwind>();
+ add<Optimizations::Local::MatchShouldNotOptimizeWhenMatchingOnIndexField>();
add<Optimizations::Local::MatchOnPrefixShouldNotSwapOnUnwind>();
add<Optimizations::Local::MatchShouldNotOptimizeWithElemMatch>();
add<Optimizations::Local::MatchWithNorOnlySplitsIndependentChildren>();