summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/query/index_bounds_builder.cpp8
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp26
2 files changed, 32 insertions, 2 deletions
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp
index 04cf9f79b05..0896be1039f 100644
--- a/src/mongo/db/query/index_bounds_builder.cpp
+++ b/src/mongo/db/query/index_bounds_builder.cpp
@@ -496,8 +496,12 @@ void IndexBoundsBuilder::_translatePredicate(const MatchExpression* expr,
*tightnessOut = IndexBoundsBuilder::EXACT;
}
- // If this invariant would fail, we would otherwise return incorrect query results.
- 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 2d3ca2d0ac5..7ec1beb9f37 100644
--- a/src/mongo/db/query/index_bounds_builder_test.cpp
+++ b/src/mongo/db/query/index_bounds_builder_test.cpp
@@ -492,6 +492,32 @@ TEST_F(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_F(IndexBoundsBuilderTest, TranslateGtMaxKeyDoesNotGenerateBounds) {
auto testIndex = buildSimpleIndexEntry();