summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@mongodb.com>2020-01-14 22:09:41 +0000
committerJacob Evans <jacob.evans@10gen.com>2020-01-15 15:09:03 -0500
commit66295a503d9c964731b5331726391ae2bdfc64d4 (patch)
treed26f56301ec1605e790d8fa68ab56651ead82f0a
parentce0a2242ca1d939cc2102857d5def9e068ebebe8 (diff)
downloadmongo-66295a503d9c964731b5331726391ae2bdfc64d4.tar.gz
SERVER-45152 Demote invariant to massert to prevent server crashes
-rw-r--r--src/mongo/db/query/index_bounds_builder.cpp9
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp26
2 files changed, 32 insertions, 3 deletions
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp
index 877ca28db99..f245e0e6487 100644
--- a/src/mongo/db/query/index_bounds_builder.cpp
+++ b/src/mongo/db/query/index_bounds_builder.cpp
@@ -374,9 +374,12 @@ void IndexBoundsBuilder::translate(const MatchExpression* expr,
translate(child, elt, index, oilOut, tightnessOut);
oilOut->complement();
- // TODO SERVER-27646: We cannot assume this invariant is true unless we build exact bounds
- // for $ne: null queries.
- // 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, 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
diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp
index 23a63dc0b0b..2f45f6fe9ba 100644
--- a/src/mongo/db/query/index_bounds_builder_test.cpp
+++ b/src/mongo/db/query/index_bounds_builder_test.cpp
@@ -589,6 +589,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) {
IndexEntry testIndex = IndexEntry(BSONObj());