summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/planner_ixselect.cpp
diff options
context:
space:
mode:
authorIan Boros <puppyofkosh@gmail.com>2019-07-19 14:51:57 -0400
committerIan Boros <puppyofkosh@gmail.com>2019-07-22 15:34:27 -0400
commitbf8fcb05e020e8eb7b99a3ca7667e0d5a289c873 (patch)
tree46d55b961962fc16059217f78635711c7c786615 /src/mongo/db/query/planner_ixselect.cpp
parentcdbb41b4c4663c5263d9351b55e5d285837b17cc (diff)
downloadmongo-bf8fcb05e020e8eb7b99a3ca7667e0d5a289c873.tar.gz
SERVER-42291 generate correct bounds for $nin null queries
Diffstat (limited to 'src/mongo/db/query/planner_ixselect.cpp')
-rw-r--r--src/mongo/db/query/planner_ixselect.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp
index f15b87b470c..84b7616a24f 100644
--- a/src/mongo/db/query/planner_ixselect.cpp
+++ b/src/mongo/db/query/planner_ixselect.cpp
@@ -440,8 +440,9 @@ bool QueryPlannerIXSelect::_compatible(const BSONElement& keyPatternElt,
// Most of the time we can't use a multikey index for a $ne: null query, however there
// are a few exceptions around $elemMatch.
- if (isNotEqualsNull &&
- !notEqualsNullCanUseIndex(index, keyPatternElt, keyPatternIdx, elemMatchContext)) {
+ const bool canUseIndexForNeNull =
+ notEqualsNullCanUseIndex(index, keyPatternElt, keyPatternIdx, elemMatchContext);
+ if (isNotEqualsNull && !canUseIndexForNeNull) {
return false;
}
@@ -451,6 +452,12 @@ bool QueryPlannerIXSelect::_compatible(const BSONElement& keyPatternElt,
if (!ime->getRegexes().empty()) {
return false;
}
+
+ // If we can't use the index for $ne to null, then we cannot use it for the
+ // case {$nin: [null, <...>]}.
+ if (!canUseIndexForNeNull && ime->hasNull()) {
+ return false;
+ }
}
}