summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-07-30 15:06:53 -0400
committerDavid Storch <david.storch@10gen.com>2014-09-10 14:41:30 -0400
commit976747c1224362120f8ee5079f542cb4f5082d32 (patch)
tree33047c787a0dde33b9b0292d135b25fe46c76271
parent7f085a7cd723ca6045e430d367e592879d92d994 (diff)
downloadmongo-976747c1224362120f8ee5079f542cb4f5082d32.tar.gz
SERVER-14706 SERVER-14706 negated $type predicates should not use an index
(cherry picked from commit 6bfddeb720b51b88533c7ae453dc5c702fdc58a5)
-rw-r--r--src/mongo/db/query/planner_ixselect.cpp3
-rw-r--r--src/mongo/db/query/query_planner_test.cpp9
2 files changed, 11 insertions, 1 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp
index 2a64df91ae8..bb23e7c2f3d 100644
--- a/src/mongo/db/query/planner_ixselect.cpp
+++ b/src/mongo/db/query/planner_ixselect.cpp
@@ -174,10 +174,11 @@ namespace mongo {
return false;
}
- // Can't index negations of MOD, REGEX, or ELEM_MATCH_VALUE.
+ // Can't index negations of MOD, REGEX, TYPE_OPERATOR, or ELEM_MATCH_VALUE.
MatchExpression::MatchType childtype = node->getChild(0)->matchType();
if (MatchExpression::REGEX == childtype ||
MatchExpression::MOD == childtype ||
+ MatchExpression::TYPE_OPERATOR == childtype ||
MatchExpression::ELEM_MATCH_VALUE == childtype) {
return false;
}
diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp
index 5b8eeef200f..b23da60bc05 100644
--- a/src/mongo/db/query/query_planner_test.cpp
+++ b/src/mongo/db/query/query_planner_test.cpp
@@ -2893,6 +2893,15 @@ namespace {
assertSolutionExists("{cscan: {dir: 1}}");
}
+ // Negated $type doesn't use the index
+ TEST_F(QueryPlannerTest, NegationTypeOperator) {
+ addIndex(BSON("i" << 1));
+ runQuery(fromjson("{i: {$not: {$type: 16}}}"));
+
+ assertNumSolutions(1U);
+ assertSolutionExists("{cscan: {dir: 1}}");
+ }
+
// Negated $elemMatch value won't use the index
TEST_F(QueryPlannerTest, NegationElemMatchValue) {
addIndex(BSON("i" << 1));