summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/indexability.h
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-07-31 18:05:06 -0400
committerDavid Storch <david.storch@10gen.com>2014-08-08 23:46:36 -0400
commit4f5703ae45f05576fac5261dc985aabd142a0a78 (patch)
tree2ecf43e36832b1a89a95616f1b1083041552718d /src/mongo/db/query/indexability.h
parentff1c6fd66530866cd04e2a8e40e368b9f565ee34 (diff)
downloadmongo-4f5703ae45f05576fac5261dc985aabd142a0a78.tar.gz
SERVER-14718 index negations below elemMatch value
Diffstat (limited to 'src/mongo/db/query/indexability.h')
-rw-r--r--src/mongo/db/query/indexability.h27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/mongo/db/query/indexability.h b/src/mongo/db/query/indexability.h
index 7791d4fad8b..7ab8007b0bf 100644
--- a/src/mongo/db/query/indexability.h
+++ b/src/mongo/db/query/indexability.h
@@ -71,11 +71,36 @@ namespace mongo {
// considered "indexable" all children of the ELEM_MATCH_VALUE
// must be "indexable" type expressions as well.
for (size_t i = 0; i < me->numChildren(); i++) {
- if (!isIndexOnOwnFieldTypeNode(me->getChild(i))) {
+ MatchExpression* child = me->getChild(i);
+
+ // Special case for NOT: If the child is a NOT, then it's the thing below
+ // the NOT that we care about.
+ if (MatchExpression::NOT == child->matchType()) {
+ MatchExpression* notChild = child->getChild(0);
+
+ if (MatchExpression::MOD == notChild->matchType() ||
+ MatchExpression::REGEX == notChild->matchType() ||
+ MatchExpression::TYPE_OPERATOR == notChild->matchType()) {
+ // We can't index negations of this kind of expression node.
+ return false;
+ }
+
+ // It's the child of the NOT that we check for indexability.
+ if (!isIndexOnOwnFieldTypeNode(notChild)) {
+ return false;
+ }
+
+ // Special handling for NOT has already been done; don't fall through.
+ continue;
+ }
+
+ if (!isIndexOnOwnFieldTypeNode(child)) {
return false;
}
}
+ // The entire ELEM_MATCH_VALUE is indexable since every one of its children
+ // is indexable.
return true;
}