From 5547f61d0abc1f81cf160f3693f741b8ce889084 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 15 Jan 2020 19:45:01 -0500 Subject: SERVER-45152 Match master negation of null behavior for consistency --- src/mongo/db/query/index_bounds_builder.cpp | 22 +++++++++++++++++++--- 1 file 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(me)->getData().type() == BSONType::jstNULL; + } + + if (me->matchType() == MatchExpression::MATCH_IN) { + const InMatchExpression* in = static_cast(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 -- cgit v1.2.1