summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@10gen.com>2020-10-09 22:56:39 -0400
committerJacob Evans <jacob.evans@10gen.com>2020-11-09 18:33:26 -0500
commit15e73dc5738d2278b688f8929aee605fe4279b0e (patch)
treec62a5631100f064361097a479a0d1a7069d8a61a /src
parent2b0d78e836ff4c4ed08212c49e93a02fc20ca669 (diff)
downloadmongo-6bdc844b4721f9b18fbee2703f1917e6b2080286.tar.gz
SERVER-51303 Fix lookup match absorbtion optimization for $typer4.4.2-rc1r4.4.2
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/pipeline/document_source_match.cpp3
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp18
2 files changed, 19 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp
index 7da9d5a3f3c..f5dc049df46 100644
--- a/src/mongo/db/pipeline/document_source_match.cpp
+++ b/src/mongo/db/pipeline/document_source_match.cpp
@@ -446,8 +446,7 @@ boost::intrusive_ptr<DocumentSourceMatch> DocumentSourceMatch::descendMatchOnPat
invariant(expression::isPathPrefixOf(descendOn, leafPath));
auto newPath = leafPath.substr(descendOn.size() + 1);
- if (node->getCategory() == MatchExpression::MatchCategory::kLeaf &&
- node->matchType() != MatchExpression::TYPE_OPERATOR) {
+ if (node->getCategory() == MatchExpression::MatchCategory::kLeaf) {
auto leafNode = static_cast<LeafMatchExpression*>(node);
leafNode->setPath(newPath);
} else if (node->getCategory() == MatchExpression::MatchCategory::kArrayMatching) {
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index 2fc38946417..44d48015332 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -519,6 +519,24 @@ TEST(PipelineOptimizationTest, LookupShouldAbsorbUnwindMatch) {
assertPipelineOptimizesAndSerializesTo(inputPipe, outputPipe, serializedPipe);
}
+TEST(PipelineOptimizationTest, LookupShouldAbsorbUnwindAndTypeMatch) {
+ string inputPipe =
+ "[{$lookup: {from: 'lookupColl', as: 'asField', localField: 'y', foreignField: "
+ "'z'}}, "
+ "{$unwind: '$asField'}, "
+ "{$match: {'asField.subfield': {$type: [2]}}}]";
+ string outputPipe =
+ "[{$lookup: {from: 'lookupColl', as: 'asField', localField: 'y', foreignField: 'z', "
+ " unwinding: {preserveNullAndEmptyArrays: false}, "
+ " matching: {subfield: {$type: [2]}}}}]";
+ string serializedPipe =
+ "[{$lookup: {from: 'lookupColl', as: 'asField', localField: 'y', foreignField: "
+ "'z'}}, "
+ "{$unwind: {path: '$asField'}}, "
+ "{$match: {'asField.subfield': {$type: [2]}}}]";
+ assertPipelineOptimizesAndSerializesTo(inputPipe, outputPipe, serializedPipe);
+}
+
TEST(PipelineOptimizationTest, LookupWithPipelineSyntaxShouldAbsorbUnwindMatch) {
string inputPipe =
"[{$lookup: {from: 'lookupColl', as: 'asField', pipeline: []}}, "