summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@10gen.com>2020-01-15 19:45:01 -0500
committerJacob Evans <jacob.evans@10gen.com>2020-01-16 16:22:39 -0500
commit5547f61d0abc1f81cf160f3693f741b8ce889084 (patch)
tree80304ff84f508c44fca3a2eff5483d79ab87df1f
parent34279b12c0748a7066a18f94c0b881608936325b (diff)
downloadmongo-r4.0.15-rc0.tar.gz
SERVER-45152 Match master negation of null behavior for consistencyr4.0.15-rc0r4.0.15
-rw-r--r--src/mongo/db/query/index_bounds_builder.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp
index f245e0e6487..503ee1f8b9d 100644
--- a/src/mongo/db/query/index_bounds_builder.cpp
+++ b/src/mongo/db/query/index_bounds_builder.cpp
@@ -109,6 +109,21 @@ bool stringMayHaveUnescapedPipe(StringData str) {
return false;
}
+bool isEqualityOrInNull(MatchExpression* me) {
+ // Because of type-bracketing, {$gte: null} and {$lte: null} are equivalent to {$eq: null}.
+ if (MatchExpression::EQ == me->matchType() || MatchExpression::GTE == me->matchType() ||
+ MatchExpression::LTE == me->matchType()) {
+ return static_cast<ComparisonMatchExpression*>(me)->getData().type() == BSONType::jstNULL;
+ }
+
+ if (me->matchType() == MatchExpression::MATCH_IN) {
+ const InMatchExpression* in = static_cast<const InMatchExpression*>(me);
+ return in->hasNull();
+ }
+
+ return false;
+}
+
} // namespace
string IndexBoundsBuilder::simpleRegex(const char* regex,
@@ -377,9 +392,10 @@ void IndexBoundsBuilder::translate(const MatchExpression* expr,
// This disables indexed negation of array inequality.
// TODO: SERVER-45233 Perform correct behavior here once indexed array inequality without
// negation's semantics are correctly determined and implemented.
- massert(ErrorCodes::InternalError,
- "Indexed negation of array inequality not supported.",
- *tightnessOut == IndexBoundsBuilder::EXACT);
+ if (!isEqualityOrInNull(child))
+ massert(ErrorCodes::InternalError,
+ "Indexed negation of array inequality not supported.",
+ *tightnessOut == IndexBoundsBuilder::EXACT);
// If the index is multikey, it doesn't matter what the tightness of the child is, we must
// return INEXACT_FETCH. Consider a multikey index on 'a' with document {a: [1, 2, 3]} and