summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/query/index_bounds_builder.cpp10
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp26
2 files changed, 32 insertions, 4 deletions
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp
index a947c02d631..279d465df20 100644
--- a/src/mongo/db/query/index_bounds_builder.cpp
+++ b/src/mongo/db/query/index_bounds_builder.cpp
@@ -447,10 +447,12 @@ void IndexBoundsBuilder::_translatePredicate(const MatchExpression* expr,
*tightnessOut = IndexBoundsBuilder::EXACT;
}
- // If this invariant would fail, we would return incorrect query results. The invariant is
- // intentionally commented out because the risk of having it crash the server outweighs the
- // benefit of picking up a subtle correctness issue on a stable version.
- // invariant(*tightnessOut == IndexBoundsBuilder::EXACT);
+ // 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 the index is multikey on this path, it doesn't matter what the tightness of the child
// is, we must return INEXACT_FETCH. Consider a multikey index on 'a' with document
diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp
index e977b419167..4d8e72b89bc 100644
--- a/src/mongo/db/query/index_bounds_builder_test.cpp
+++ b/src/mongo/db/query/index_bounds_builder_test.cpp
@@ -601,6 +601,32 @@ TEST(IndexBoundsBuilderTest, TranslateGtMinKey) {
ASSERT_EQUALS(tightness, IndexBoundsBuilder::EXACT);
}
+TEST_F(IndexBoundsBuilderTest, DontCrashOnNegationOfArrayInequality) {
+ BSONObj keyPattern = BSON("a" << 1);
+ auto testIndex = IndexEntry(keyPattern,
+ IndexNames::nameToType(IndexNames::findPluginName(keyPattern)),
+ true, // multikey
+ {},
+ {},
+ false, // sparse
+ false, // unique
+ IndexEntry::Identifier{"test_foo"},
+ nullptr, // filterExpr
+ BSONObj(),
+ nullptr,
+ nullptr);
+
+ BSONObj obj = fromjson("{a: {$not: {$lt: [\"here\", {}, false]}}}");
+ auto expr = MatchExpression::optimize(parseMatchExpression(obj));
+ BSONElement elt = obj.firstElement();
+ OrderedIntervalList oil;
+ IndexBoundsBuilder::BoundsTightness tightness;
+ // TODO: SERVER-45233 This should succeed rather than throwing code.
+ ASSERT_THROWS_CODE(IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness),
+ DBException,
+ ErrorCodes::InternalError);
+}
+
// Nothing can be greater than MaxKey so the resulting index bounds would be a useless empty range.
TEST(IndexBoundsBuilderTest, TranslateGtMaxKeyDoesNotGenerateBounds) {
auto testIndex = buildSimpleIndexEntry();