summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-04-22 10:58:33 -0400
committerDan Pasette <dan@mongodb.com>2014-04-30 10:36:30 -0400
commit6a900b9d4f43f866c1762247689c60944889ce08 (patch)
tree6afb33726d5aed548a795474b1f802b655c39eeb
parentfce2652dca83bce5fcb823fccbd282c5815a899b (diff)
downloadmongo-6a900b9d4f43f866c1762247689c60944889ce08.tar.gz
SERVER-13677 traverse through ALL when finding predicates inside elemMatch object
(cherry picked from commit 54bdb39ba62c25ef59221fcab866501c02a06047)
-rw-r--r--src/mongo/db/query/planner_access.cpp2
-rw-r--r--src/mongo/db/query/query_planner_test.cpp35
2 files changed, 36 insertions, 1 deletions
diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp
index 0dc1913ec57..fc0fb1c2030 100644
--- a/src/mongo/db/query/planner_access.cpp
+++ b/src/mongo/db/query/planner_access.cpp
@@ -490,7 +490,7 @@ namespace mongo {
out->push_back(child);
}
else if (MatchExpression::AND == child->matchType() ||
- MatchExpression::ELEM_MATCH_OBJECT == child->matchType()) {
+ Indexability::arrayUsesIndexOnChildren(child)) {
findElemMatchChildren(child, out);
}
}
diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp
index 83092ddb49e..5523675d9c5 100644
--- a/src/mongo/db/query/query_planner_test.cpp
+++ b/src/mongo/db/query/query_planner_test.cpp
@@ -1230,6 +1230,41 @@ namespace {
"node: {ixscan: {filter: null, pattern: {'foo.b': 1}}}}}");*/
}
+ // SERVER-13677
+ TEST_F(QueryPlannerTest, ElemMatchWithAllElemMatchChild) {
+ addIndex(BSON("a.b.c.d" << 1));
+ runQuery(fromjson("{z: 1, 'a.b': {$elemMatch: {c: {$all: [{$elemMatch: {d: 0}}]}}}}"));
+
+ assertNumSolutions(2U);
+ assertSolutionExists("{cscan: {dir: 1}}");
+ assertSolutionExists("{fetch: {node: {ixscan: {pattern: {'a.b.c.d': 1}}}}}");
+ }
+
+ // SERVER-13677
+ TEST_F(QueryPlannerTest, ElemMatchWithAllElemMatchChild2) {
+ // true means multikey
+ addIndex(BSON("a.b.c.d" << 1), true);
+ runQuery(fromjson("{'a.b': {$elemMatch: {c: {$all: "
+ "[{$elemMatch: {d: {$gt: 1, $lt: 3}}}]}}}}"));
+
+ assertNumSolutions(2U);
+ assertSolutionExists("{cscan: {dir: 1}}");
+ assertSolutionExists("{fetch: {node: {ixscan: {pattern: {'a.b.c.d': 1}, "
+ "bounds: {'a.b.c.d': [[-Infinity,3,true,false]]}}}}}");
+ }
+
+ // SERVER-13677
+ TEST_F(QueryPlannerTest, ElemMatchWithAllChild) {
+ // true means multikey
+ addIndex(BSON("a.b.c" << 1), true);
+ runQuery(fromjson("{z: 1, 'a.b': {$elemMatch: {c: {$all: [4, 5, 6]}}}}"));
+
+ assertNumSolutions(2U);
+ assertSolutionExists("{cscan: {dir: 1}}");
+ assertSolutionExists("{fetch: {node: {ixscan: {pattern: {'a.b.c': 1}, "
+ "bounds: {'a.b.c': [[4,4,true,true]]}}}}}");
+ }
+
TEST_F(QueryPlannerTest, ElemMatchValueMatch) {
addIndex(BSON("foo" << 1));
addIndex(BSON("foo" << 1 << "bar" << 1));