diff options
author | Jacob Evans <jacob.evans@10gen.com> | 2018-11-30 17:31:15 -0500 |
---|---|---|
committer | Jacob Evans <jacob.evans@10gen.com> | 2018-12-14 15:27:42 -0500 |
commit | ac39ac47d776bbd0f442f945d4ae6091b73cfb03 (patch) | |
tree | adfea7594dc25d87b76a6fb4b9db05dbfc38dbc3 /src/mongo/db/query/index_bounds_builder_test.cpp | |
parent | 333b35057d35230ad5bc868bd0eaa7423d9aceb4 (diff) | |
download | mongo-ac39ac47d776bbd0f442f945d4ae6091b73cfb03.tar.gz |
SERVER-38069 Ensure WT transactions are not re-opened during plan updates
Diffstat (limited to 'src/mongo/db/query/index_bounds_builder_test.cpp')
-rw-r--r-- | src/mongo/db/query/index_bounds_builder_test.cpp | 354 |
1 files changed, 190 insertions, 164 deletions
diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp index 0bb9f2638ee..25bc1c3f523 100644 --- a/src/mongo/db/query/index_bounds_builder_test.cpp +++ b/src/mongo/db/query/index_bounds_builder_test.cpp @@ -58,6 +58,25 @@ double positiveInfinity = numeric_limits<double>::infinity(); double NaN = numeric_limits<double>::quiet_NaN(); /** + * Make a minimal IndexEntry from just an optional key pattern. A dummy name will be added. An empty + * key pattern will be used if none is provided. + */ +IndexEntry buildSimpleIndexEntry(const BSONObj& kp = BSONObj()) { + return {kp, + IndexNames::nameToType(IndexNames::findPluginName(kp)), + false, + {}, + {}, + false, + false, + CoreIndexInfo::Identifier("test_foo"), + nullptr, + {}, + nullptr, + nullptr}; +} + +/** * Utility function to create MatchExpression */ MatchExpression* parseMatchExpression(const BSONObj& obj) { @@ -75,7 +94,7 @@ MatchExpression* parseMatchExpression(const BSONObj& obj) { void testTranslateAndUnion(const vector<BSONObj>& toUnion, OrderedIntervalList* oilOut, IndexBoundsBuilder::BoundsTightness* tightnessOut) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); for (vector<BSONObj>::const_iterator it = toUnion.begin(); it != toUnion.end(); ++it) { unique_ptr<MatchExpression> expr(parseMatchExpression(*it)); @@ -95,7 +114,7 @@ void testTranslateAndUnion(const vector<BSONObj>& toUnion, void testTranslateAndIntersect(const vector<BSONObj>& toIntersect, OrderedIntervalList* oilOut, IndexBoundsBuilder::BoundsTightness* tightnessOut) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); for (vector<BSONObj>::const_iterator it = toIntersect.begin(); it != toIntersect.end(); ++it) { unique_ptr<MatchExpression> expr(parseMatchExpression(*it)); @@ -119,7 +138,7 @@ void testTranslateAndIntersect(const vector<BSONObj>& toIntersect, void testTranslate(const vector<std::pair<BSONObj, bool>>& constraints, OrderedIntervalList* oilOut, IndexBoundsBuilder::BoundsTightness* tightnessOut) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); for (vector<std::pair<BSONObj, bool>>::const_iterator it = constraints.begin(); it != constraints.end(); @@ -156,7 +175,7 @@ bool testSingleInterval(IndexBounds bounds) { // TEST(IndexBoundsBuilderTest, TranslateElemMatchValue) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); // Bounds generated should be the same as the embedded expression // except for the tightness. BSONObj obj = fromjson("{a: {$elemMatch: {$gt: 2}}}"); @@ -178,7 +197,7 @@ TEST(IndexBoundsBuilderTest, TranslateElemMatchValue) { // TEST(IndexBoundsBuilderTest, TranslateLteNumber) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lte: 1}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -194,7 +213,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteNumber) { } TEST(IndexBoundsBuilderTest, TranslateLteNumberMin) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lte" << numberMin)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -210,7 +229,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteNumberMin) { } TEST(IndexBoundsBuilderTest, TranslateLteNegativeInfinity) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lte: -Infinity}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -226,7 +245,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteNegativeInfinity) { } TEST(IndexBoundsBuilderTest, TranslateLteObject) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lte: {b: 1}}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -241,7 +260,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteObject) { } TEST(IndexBoundsBuilderTest, TranslateLteCode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lte" << BSONCode("function(){ return 0; }"))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -257,7 +276,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteCode) { } TEST(IndexBoundsBuilderTest, TranslateLteCodeWScope) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lte" << BSONCodeWScope("this.b == c", BSON("c" << 1)))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -274,7 +293,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteCodeWScope) { } TEST(IndexBoundsBuilderTest, TranslateLteMinKey) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lte" << MINKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -290,7 +309,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteMinKey) { } TEST(IndexBoundsBuilderTest, TranslateLteMaxKey) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lte" << MAXKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -306,7 +325,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteMaxKey) { } TEST(IndexBoundsBuilderTest, TranslateLtNumber) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lt: 1}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -322,7 +341,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtNumber) { } TEST(IndexBoundsBuilderTest, TranslateLtNumberMin) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lt" << numberMin)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -338,7 +357,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtNumberMin) { } TEST(IndexBoundsBuilderTest, TranslateLtNegativeInfinity) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lt: -Infinity}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -351,7 +370,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtNegativeInfinity) { } TEST(IndexBoundsBuilderTest, TranslateLtDate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << LT << Date_t::fromMillisSinceEpoch(5000)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -367,7 +386,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtDate) { } TEST(IndexBoundsBuilderTest, TranslateLtObject) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lt: {b: 1}}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -383,7 +402,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtObject) { } TEST(IndexBoundsBuilderTest, TranslateLtCode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lt" << BSONCode("function(){ return 0; }"))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -399,7 +418,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtCode) { } TEST(IndexBoundsBuilderTest, TranslateLtCodeWScope) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lt" << BSONCodeWScope("this.b == c", BSON("c" << 1)))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -417,7 +436,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtCodeWScope) { // Nothing can be less than MinKey so the resulting index bounds would be a useless empty range. TEST(IndexBoundsBuilderTest, TranslateLtMinKeyDoesNotGenerateBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lt" << MINKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -430,7 +449,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtMinKeyDoesNotGenerateBounds) { } TEST(IndexBoundsBuilderTest, TranslateLtMaxKey) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$lt" << MAXKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -446,7 +465,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtMaxKey) { } TEST(IndexBoundsBuilderTest, TranslateGtTimestamp) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << GT << Timestamp(2, 3)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -465,7 +484,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtTimestamp) { } TEST(IndexBoundsBuilderTest, TranslateGtNumber) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gt: 1}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -481,7 +500,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtNumber) { } TEST(IndexBoundsBuilderTest, TranslateGtNumberMax) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gt" << numberMax)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -497,7 +516,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtNumberMax) { } TEST(IndexBoundsBuilderTest, TranslateGtPositiveInfinity) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gt: Infinity}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -510,7 +529,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtPositiveInfinity) { } TEST(IndexBoundsBuilderTest, TranslateGtString) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gt: 'abc'}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -526,7 +545,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtString) { } TEST(IndexBoundsBuilderTest, TranslateGtObject) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gt: {b: 1}}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -542,7 +561,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtObject) { } TEST(IndexBoundsBuilderTest, TranslateGtCode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gt" << BSONCode("function(){ return 0; }"))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -558,7 +577,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtCode) { } TEST(IndexBoundsBuilderTest, TranslateGtCodeWScope) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gt" << BSONCodeWScope("this.b == c", BSON("c" << 1)))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -574,7 +593,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtCodeWScope) { } TEST(IndexBoundsBuilderTest, TranslateGtMinKey) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gt" << MINKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -591,7 +610,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtMinKey) { // Nothing can be greater than MaxKey so the resulting index bounds would be a useless empty range. TEST(IndexBoundsBuilderTest, TranslateGtMaxKeyDoesNotGenerateBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gt" << MAXKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -604,7 +623,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtMaxKeyDoesNotGenerateBounds) { } TEST(IndexBoundsBuilderTest, TranslateGteNumber) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gte: 1}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -620,7 +639,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteNumber) { } TEST(IndexBoundsBuilderTest, TranslateGteNumberMax) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gte" << numberMax)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -636,7 +655,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteNumberMax) { } TEST(IndexBoundsBuilderTest, TranslateGtePositiveInfinity) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gte: Infinity}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -652,7 +671,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtePositiveInfinity) { } TEST(IndexBoundsBuilderTest, TranslateGteObject) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gte: {b: 1}}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -668,7 +687,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteObject) { } TEST(IndexBoundsBuilderTest, TranslateGteCode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gte" << BSONCode("function(){ return 0; }"))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -684,7 +703,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteCode) { } TEST(IndexBoundsBuilderTest, TranslateGteCodeWScope) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gte" << BSONCodeWScope("this.b == c", BSON("c" << 1)))); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -700,7 +719,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteCodeWScope) { } TEST(IndexBoundsBuilderTest, TranslateGteMinKey) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gte" << MINKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -716,7 +735,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteMinKey) { } TEST(IndexBoundsBuilderTest, TranslateGteMaxKey) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$gte" << MAXKEY)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -732,7 +751,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteMaxKey) { } TEST(IndexBoundsBuilderTest, TranslateEqualNan) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: NaN}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -747,7 +766,7 @@ TEST(IndexBoundsBuilderTest, TranslateEqualNan) { } TEST(IndexBoundsBuilderTest, TranslateLtNan) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lt: NaN}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -760,7 +779,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtNan) { } TEST(IndexBoundsBuilderTest, TranslateLteNan) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$lte: NaN}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -775,7 +794,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteNan) { } TEST(IndexBoundsBuilderTest, TranslateGtNan) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gt: NaN}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -788,7 +807,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtNan) { } TEST(IndexBoundsBuilderTest, TranslateGteNan) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$gte: NaN}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -803,7 +822,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteNan) { } TEST(IndexBoundsBuilderTest, TranslateEqual) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << 4); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -820,7 +839,7 @@ TEST(IndexBoundsBuilderTest, TranslateEqual) { TEST(IndexBoundsBuilderTest, TranslateExprEqual) { BSONObj keyPattern = BSON("a" << 1); BSONElement elt = keyPattern.firstElement(); - IndexEntry testIndex{keyPattern}; + auto testIndex = buildSimpleIndexEntry(keyPattern); BSONObj obj = BSON("a" << BSON("$_internalExprEq" << 4)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); OrderedIntervalList oil; @@ -837,7 +856,7 @@ TEST(IndexBoundsBuilderTest, TranslateExprEqualToStringRespectsCollation) { BSONObj keyPattern = BSON("a" << 1); BSONElement elt = keyPattern.firstElement(); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex{keyPattern}; + auto testIndex = buildSimpleIndexEntry(keyPattern); testIndex.collator = &collator; BSONObj obj = BSON("a" << BSON("$_internalExprEq" @@ -857,7 +876,7 @@ TEST(IndexBoundsBuilderTest, TranslateExprEqualToStringRespectsCollation) { TEST(IndexBoundsBuilderTest, TranslateExprEqualHashedIndex) { BSONObj keyPattern = fromjson("{a: 'hashed'}"); BSONElement elt = keyPattern.firstElement(); - IndexEntry testIndex{keyPattern}; + auto testIndex = buildSimpleIndexEntry(keyPattern); BSONObj obj = BSON("a" << BSON("$_internalExprEq" << 4)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); OrderedIntervalList oil; @@ -880,7 +899,7 @@ TEST(IndexBoundsBuilderTest, TranslateExprEqualHashedIndex) { TEST(IndexBoundsBuilderTest, TranslateExprEqualToNullIsInexactFetch) { BSONObj keyPattern = BSON("a" << 1); BSONElement elt = keyPattern.firstElement(); - IndexEntry testIndex{keyPattern}; + auto testIndex = buildSimpleIndexEntry(keyPattern); BSONObj obj = BSON("a" << BSON("$_internalExprEq" << BSONNULL)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); OrderedIntervalList oil; @@ -897,7 +916,7 @@ TEST(IndexBoundsBuilderTest, TranslateExprEqualToNullIsInexactFetch) { } TEST(IndexBoundsBuilderTest, TranslateArrayEqualBasic) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: [1, 2, 3]}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -915,7 +934,7 @@ TEST(IndexBoundsBuilderTest, TranslateArrayEqualBasic) { } TEST(IndexBoundsBuilderTest, TranslateIn) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$in: [8, 44, -1, -3]}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -936,7 +955,7 @@ TEST(IndexBoundsBuilderTest, TranslateIn) { } TEST(IndexBoundsBuilderTest, TranslateInArray) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$in: [[1], 2]}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -955,7 +974,7 @@ TEST(IndexBoundsBuilderTest, TranslateInArray) { } TEST(IndexBoundsBuilderTest, TranslateLteBinData) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson( "{a: {$lte: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA'," "$type: '00'}}}"); @@ -976,7 +995,7 @@ TEST(IndexBoundsBuilderTest, TranslateLteBinData) { } TEST(IndexBoundsBuilderTest, TranslateLtBinData) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson( "{a: {$lt: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA'," "$type: '00'}}}"); @@ -997,7 +1016,7 @@ TEST(IndexBoundsBuilderTest, TranslateLtBinData) { } TEST(IndexBoundsBuilderTest, TranslateGtBinData) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson( "{a: {$gt: {$binary: '////////////////////////////'," "$type: '00'}}}"); @@ -1018,7 +1037,7 @@ TEST(IndexBoundsBuilderTest, TranslateGtBinData) { } TEST(IndexBoundsBuilderTest, TranslateGteBinData) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson( "{a: {$gte: {$binary: '////////////////////////////'," "$type: '00'}}}"); @@ -1043,7 +1062,7 @@ TEST(IndexBoundsBuilderTest, TranslateGteBinData) { // TEST(IndexBoundsBuilderTest, TypeNumber) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: 'number'}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1070,7 +1089,7 @@ TEST(IndexBoundsBuilderTest, TypeNumber) { // TEST(IndexBoundsBuilderTest, ExistsTrue) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$exists: true}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1085,7 +1104,7 @@ TEST(IndexBoundsBuilderTest, ExistsTrue) { } TEST(IndexBoundsBuilderTest, ExistsFalse) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$exists: false}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1100,13 +1119,20 @@ TEST(IndexBoundsBuilderTest, ExistsFalse) { } TEST(IndexBoundsBuilderTest, ExistsTrueSparse) { - IndexEntry testIndex = IndexEntry(BSONObj(), - false, // multikey - true, // sparse - false, // unique - IndexEntry::Identifier{"exists_true_sparse"}, - nullptr, // filterExpr - BSONObj()); + auto keyPattern = BSONObj(); + IndexEntry testIndex = + IndexEntry(keyPattern, + IndexNames::nameToType(IndexNames::findPluginName(keyPattern)), + false, // multikey + {}, + {}, + true, // sparse + false, // unique + IndexEntry::Identifier{"exists_true_sparse"}, + nullptr, // filterExpr + BSONObj(), + nullptr, + nullptr); BSONObj obj = fromjson("{a: {$exists: true}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1125,7 +1151,7 @@ TEST(IndexBoundsBuilderTest, ExistsTrueSparse) { // TEST(IndexBoundsBuilderTest, UnionTwoLt) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toUnion; toUnion.push_back(fromjson("{a: {$lt: 1}}")); toUnion.push_back(fromjson("{a: {$lt: 5}}")); @@ -1141,7 +1167,7 @@ TEST(IndexBoundsBuilderTest, UnionTwoLt) { } TEST(IndexBoundsBuilderTest, UnionDupEq) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toUnion; toUnion.push_back(fromjson("{a: 1}")); toUnion.push_back(fromjson("{a: 5}")); @@ -1159,7 +1185,7 @@ TEST(IndexBoundsBuilderTest, UnionDupEq) { } TEST(IndexBoundsBuilderTest, UnionGtLt) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toUnion; toUnion.push_back(fromjson("{a: {$gt: 1}}")); toUnion.push_back(fromjson("{a: {$lt: 3}}")); @@ -1175,7 +1201,7 @@ TEST(IndexBoundsBuilderTest, UnionGtLt) { } TEST(IndexBoundsBuilderTest, UnionTwoEmptyRanges) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<std::pair<BSONObj, bool>> constraints; constraints.push_back(std::make_pair(fromjson("{a: {$gt: 1}}"), true)); constraints.push_back(std::make_pair(fromjson("{a: {$lte: 0}}"), true)); @@ -1192,7 +1218,7 @@ TEST(IndexBoundsBuilderTest, UnionTwoEmptyRanges) { // TEST(IndexBoundsBuilderTest, IntersectTwoLt) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: {$lt: 1}}")); toIntersect.push_back(fromjson("{a: {$lt: 5}}")); @@ -1208,7 +1234,7 @@ TEST(IndexBoundsBuilderTest, IntersectTwoLt) { } TEST(IndexBoundsBuilderTest, IntersectEqGte) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: 1}}")); toIntersect.push_back(fromjson("{a: {$gte: 1}}")); @@ -1223,7 +1249,7 @@ TEST(IndexBoundsBuilderTest, IntersectEqGte) { } TEST(IndexBoundsBuilderTest, IntersectGtLte) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: {$gt: 0}}")); toIntersect.push_back(fromjson("{a: {$lte: 10}}")); @@ -1238,7 +1264,7 @@ TEST(IndexBoundsBuilderTest, IntersectGtLte) { } TEST(IndexBoundsBuilderTest, IntersectGtIn) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: {$gt: 4}}")); toIntersect.push_back(fromjson("{a: {$in: [1,2,3,4,5,6]}}")); @@ -1255,7 +1281,7 @@ TEST(IndexBoundsBuilderTest, IntersectGtIn) { } TEST(IndexBoundsBuilderTest, IntersectionIsPointInterval) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: {$gte: 1}}")); toIntersect.push_back(fromjson("{a: {$lte: 1}}")); @@ -1270,7 +1296,7 @@ TEST(IndexBoundsBuilderTest, IntersectionIsPointInterval) { } TEST(IndexBoundsBuilderTest, IntersectFullyContained) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: {$gt: 5}}")); toIntersect.push_back(fromjson("{a: {$lt: 15}}")); @@ -1287,7 +1313,7 @@ TEST(IndexBoundsBuilderTest, IntersectFullyContained) { } TEST(IndexBoundsBuilderTest, EmptyIntersection) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: 1}}")); toIntersect.push_back(fromjson("{a: {$gte: 2}}")); @@ -1303,7 +1329,7 @@ TEST(IndexBoundsBuilderTest, EmptyIntersection) { // TEST(IndexBoundsBuilderTest, TranslateMod) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$mod: [2, 0]}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1323,7 +1349,7 @@ TEST(IndexBoundsBuilderTest, TranslateMod) { // TEST(SimpleRegexTest, RootedLine) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^foo", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "foo"); @@ -1331,7 +1357,7 @@ TEST(SimpleRegexTest, RootedLine) { } TEST(SimpleRegexTest, RootedString) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("\\Afoo", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "foo"); @@ -1339,7 +1365,7 @@ TEST(SimpleRegexTest, RootedString) { } TEST(SimpleRegexTest, RootedOptionalFirstChar) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^f?oo", "", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1347,7 +1373,7 @@ TEST(SimpleRegexTest, RootedOptionalFirstChar) { } TEST(SimpleRegexTest, RootedOptionalSecondChar) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^fz?oo", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "f"); @@ -1355,7 +1381,7 @@ TEST(SimpleRegexTest, RootedOptionalSecondChar) { } TEST(SimpleRegexTest, RootedMultiline) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^foo", "m", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1363,7 +1389,7 @@ TEST(SimpleRegexTest, RootedMultiline) { } TEST(SimpleRegexTest, RootedStringMultiline) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("\\Afoo", "m", testIndex, &tightness); ASSERT_EQUALS(prefix, "foo"); @@ -1371,7 +1397,7 @@ TEST(SimpleRegexTest, RootedStringMultiline) { } TEST(SimpleRegexTest, RootedCaseInsensitiveMulti) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("\\Afoo", "mi", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1379,7 +1405,7 @@ TEST(SimpleRegexTest, RootedCaseInsensitiveMulti) { } TEST(SimpleRegexTest, RootedComplex) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex( "\\Af \t\vo\n\ro \\ \\# #comment", "mx", testIndex, &tightness); @@ -1388,7 +1414,7 @@ TEST(SimpleRegexTest, RootedComplex) { } TEST(SimpleRegexTest, RootedLiteral) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qasdf\\E", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "asdf"); @@ -1396,7 +1422,7 @@ TEST(SimpleRegexTest, RootedLiteral) { } TEST(SimpleRegexTest, RootedLiteralWithExtra) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qasdf\\E.*", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "asdf"); @@ -1404,7 +1430,7 @@ TEST(SimpleRegexTest, RootedLiteralWithExtra) { } TEST(SimpleRegexTest, RootedLiteralNoEnd) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qasdf", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "asdf"); @@ -1412,7 +1438,7 @@ TEST(SimpleRegexTest, RootedLiteralNoEnd) { } TEST(SimpleRegexTest, RootedLiteralBackslash) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qasdf\\\\E", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "asdf\\"); @@ -1420,7 +1446,7 @@ TEST(SimpleRegexTest, RootedLiteralBackslash) { } TEST(SimpleRegexTest, RootedLiteralDotStar) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qas.*df\\E", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "as.*df"); @@ -1428,7 +1454,7 @@ TEST(SimpleRegexTest, RootedLiteralDotStar) { } TEST(SimpleRegexTest, RootedLiteralNestedEscape) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qas\\Q[df\\E", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "as\\Q[df"); @@ -1436,7 +1462,7 @@ TEST(SimpleRegexTest, RootedLiteralNestedEscape) { } TEST(SimpleRegexTest, RootedLiteralNestedEscapeEnd) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^\\Qas\\E\\\\E\\Q$df\\E", "", testIndex, &tightness); @@ -1447,7 +1473,7 @@ TEST(SimpleRegexTest, RootedLiteralNestedEscapeEnd) { // An anchored regular expression that uses the "|" operator is not considered "simple" and has // non-tight index bounds. TEST(SimpleRegexTest, PipeCharacterUsesInexactBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^(a(a|$)|b", "", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1455,7 +1481,7 @@ TEST(SimpleRegexTest, PipeCharacterUsesInexactBounds) { } TEST(SimpleRegexTest, PipeCharacterUsesInexactBoundsWithTwoPrefixes) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^(a(a|$)|^b", "", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1463,7 +1489,7 @@ TEST(SimpleRegexTest, PipeCharacterUsesInexactBoundsWithTwoPrefixes) { } TEST(SimpleRegexTest, PipeCharacterPrecededByEscapedBackslashUsesInexactBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex(R"(^a\\|b)", "", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1477,7 +1503,7 @@ TEST(SimpleRegexTest, PipeCharacterPrecededByEscapedBackslashUsesInexactBounds) // However, a regular expression with an escaped pipe (that is, using no special meaning) can use // exact index bounds. TEST(SimpleRegexTest, PipeCharacterEscapedWithBackslashUsesExactBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex(R"(^a\|b)", "", testIndex, &tightness); ASSERT_EQUALS(prefix, "a|b"); @@ -1489,7 +1515,7 @@ TEST(SimpleRegexTest, PipeCharacterEscapedWithBackslashUsesExactBounds) { } TEST(SimpleRegexTest, FalsePositiveOnPipeInQEEscapeSequenceUsesInexactBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex(R"(^\Q|\E)", "", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1497,7 +1523,7 @@ TEST(SimpleRegexTest, FalsePositiveOnPipeInQEEscapeSequenceUsesInexactBounds) { } TEST(SimpleRegexTest, FalsePositiveOnPipeInCharacterClassUsesInexactBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex(R"(^[|])", "", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1506,7 +1532,7 @@ TEST(SimpleRegexTest, FalsePositiveOnPipeInCharacterClassUsesInexactBounds) { // SERVER-9035 TEST(SimpleRegexTest, RootedSingleLineMode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("^foo", "s", testIndex, &tightness); ASSERT_EQUALS(prefix, "foo"); @@ -1515,7 +1541,7 @@ TEST(SimpleRegexTest, RootedSingleLineMode) { // SERVER-9035 TEST(SimpleRegexTest, NonRootedSingleLineMode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex("foo", "s", testIndex, &tightness); ASSERT_EQUALS(prefix, ""); @@ -1524,7 +1550,7 @@ TEST(SimpleRegexTest, NonRootedSingleLineMode) { // SERVER-9035 TEST(SimpleRegexTest, RootedComplexSingleLineMode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); IndexBoundsBuilder::BoundsTightness tightness; string prefix = IndexBoundsBuilder::simpleRegex( "\\Af \t\vo\n\ro \\ \\# #comment", "msx", testIndex, &tightness); @@ -1534,7 +1560,7 @@ TEST(SimpleRegexTest, RootedComplexSingleLineMode) { TEST(SimpleRegexTest, RootedRegexCantBeIndexedTightlyIfIndexHasCollation) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; IndexBoundsBuilder::BoundsTightness tightness; @@ -1548,7 +1574,7 @@ TEST(SimpleRegexTest, RootedRegexCantBeIndexedTightlyIfIndexHasCollation) { // TEST(IndexBoundsBuilderTest, SimpleNonPrefixRegex) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: /foo/}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1565,7 +1591,7 @@ TEST(IndexBoundsBuilderTest, SimpleNonPrefixRegex) { } TEST(IndexBoundsBuilderTest, NonSimpleRegexWithPipe) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: /^foo.*|bar/}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1582,7 +1608,7 @@ TEST(IndexBoundsBuilderTest, NonSimpleRegexWithPipe) { } TEST(IndexBoundsBuilderTest, SimpleRegexSingleLineMode) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: /^foo/s}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1600,7 +1626,7 @@ TEST(IndexBoundsBuilderTest, SimpleRegexSingleLineMode) { } TEST(IndexBoundsBuilderTest, SimplePrefixRegex) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: /^foo/}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1831,7 +1857,7 @@ BSONObj maxKeyIntObj(int start) { // Expected oil: [MinKey, 3), (3, MaxKey] TEST(IndexBoundsBuilderTest, SimpleNE) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = BSON("a" << BSON("$ne" << 3)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1848,7 +1874,7 @@ TEST(IndexBoundsBuilderTest, SimpleNE) { } TEST(IndexBoundsBuilderTest, IntersectWithNE) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toIntersect; toIntersect.push_back(fromjson("{a: {$gt: 1}}")); toIntersect.push_back(fromjson("{a: {$ne: 2}}}")); @@ -1866,7 +1892,7 @@ TEST(IndexBoundsBuilderTest, IntersectWithNE) { } TEST(IndexBoundsBuilderTest, UnionizeWithNE) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); vector<BSONObj> toUnionize; toUnionize.push_back(fromjson("{a: {$ne: 3}}")); toUnionize.push_back(fromjson("{a: {$ne: 4}}}")); @@ -1882,7 +1908,7 @@ TEST(IndexBoundsBuilderTest, UnionizeWithNE) { // Test $type bounds for Code BSON type. TEST(IndexBoundsBuilderTest, CodeTypeBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: 13}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1907,7 +1933,7 @@ TEST(IndexBoundsBuilderTest, CodeTypeBounds) { // Test $type bounds for Code With Scoped BSON type. TEST(IndexBoundsBuilderTest, CodeWithScopeTypeBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: 15}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1932,7 +1958,7 @@ TEST(IndexBoundsBuilderTest, CodeWithScopeTypeBounds) { // Test $type bounds for double BSON type. TEST(IndexBoundsBuilderTest, DoubleTypeBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: 1}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1956,7 +1982,7 @@ TEST(IndexBoundsBuilderTest, DoubleTypeBounds) { } TEST(IndexBoundsBuilderTest, TypeArrayBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: 'array'}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -1979,7 +2005,7 @@ TEST(IndexBoundsBuilderTest, TypeArrayBounds) { TEST(IndexBoundsBuilderTest, TranslateEqualityToStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = BSON("a" @@ -2001,7 +2027,7 @@ TEST(IndexBoundsBuilderTest, TranslateEqualityToStringWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateEqualityToNonStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = BSON("a" << 3); @@ -2033,7 +2059,7 @@ void assertBoundsRepresentEqualsNull(const OrderedIntervalList& oil) { TEST(IndexBoundsBuilderTest, TranslateEqualsToNullShouldBuildInexactBounds) { BSONObj indexPattern = BSON("a" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); BSONObj obj = BSON("a" << BSONNULL); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); @@ -2050,7 +2076,7 @@ TEST(IndexBoundsBuilderTest, TranslateEqualsToNullShouldBuildInexactBounds) { TEST(IndexBoundsBuilderTest, TranslateDottedEqualsToNullShouldBuildInexactBounds) { BSONObj indexPattern = BSON("a.b" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); BSONObj obj = BSON("a.b" << BSONNULL); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); @@ -2067,7 +2093,7 @@ TEST(IndexBoundsBuilderTest, TranslateDottedEqualsToNullShouldBuildInexactBounds TEST(IndexBoundsBuilderTest, TranslateEqualsToNullMultiKeyShouldBuildInexactBounds) { BSONObj indexPattern = BSON("a" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.multikey = true; BSONObj obj = BSON("a" << BSONNULL); @@ -2086,7 +2112,7 @@ TEST(IndexBoundsBuilderTest, TranslateEqualsToNullMultiKeyShouldBuildInexactBoun TEST(IndexBoundsBuilderTest, TranslateEqualsToNullShouldBuildTwoIntervalsForHashedIndex) { BSONObj indexPattern = BSON("a" << "hashed"); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.type = IndexType::INDEX_HASHED; BSONObj obj = BSON("a" << BSONNULL); @@ -2153,7 +2179,7 @@ void assertBoundsRepresentNotEqualsNull(const OrderedIntervalList& oil) { TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildExactBoundsIfIndexIsNotMultiKey) { BSONObj indexPattern = BSON("a" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); BSONObj obj = BSON("a" << BSON("$ne" << BSONNULL)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); @@ -2172,7 +2198,7 @@ TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildExactBoundsIfInde TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildExactBoundsIfIndexIsNotMultiKeyOnRelevantPath) { BSONObj indexPattern = BSON("a" << 1 << "b" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.multikeyPaths = {{}, {0}}; // "a" is not multi-key, but "b" is. BSONObj obj = BSON("a" << BSON("$ne" << BSONNULL)); @@ -2191,7 +2217,7 @@ TEST(IndexBoundsBuilderTest, TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildExactBoundsOnReverseIndex) { BSONObj indexPattern = BSON("a" << -1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); BSONObj obj = BSON("a" << BSON("$ne" << BSONNULL)); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); @@ -2209,7 +2235,7 @@ TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildExactBoundsOnReve TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildInexactBoundsIfIndexIsMultiKey) { BSONObj indexPattern = BSON("a" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.multikey = true; BSONObj matchObj = BSON("a" << BSON("$ne" << BSONNULL)); @@ -2228,7 +2254,7 @@ TEST(IndexBoundsBuilderTest, TranslateNotEqualToNullShouldBuildInexactBoundsIfIn TEST(IndexBoundsBuilderTest, TranslateDottedElemMatchValueNotEqualToNullShouldBuildExactBoundsIfIsMultiKeyOnThatPath) { BSONObj indexPattern = BSON("a.b" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.multikeyPaths = {{1}}; // "a.b" is multikey. BSONObj matchObj = BSON("a.b" << BSON("$elemMatch" << BSON("$ne" << BSONNULL))); @@ -2247,7 +2273,7 @@ TEST(IndexBoundsBuilderTest, TEST(IndexBoundsBuilderTest, TranslateDottedFieldNotEqualToNullShouldBuildInexactBoundsIfIndexIsMultiKey) { BSONObj indexPattern = BSON("a.b" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.multikey = true; BSONObj matchObj = BSON("a.b" << BSON("$ne" << BSONNULL)); @@ -2266,7 +2292,7 @@ TEST(IndexBoundsBuilderTest, TEST(IndexBoundsBuilderTest, TranslateElemMatchValueNotEqualToNullShouldBuildInexactBoundsIfIndexIsMultiKey) { BSONObj indexPattern = BSON("a" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); testIndex.multikey = true; BSONObj obj = BSON("a" << BSON("$elemMatch" << BSON("$ne" << BSONNULL))); @@ -2285,7 +2311,7 @@ TEST(IndexBoundsBuilderTest, TEST(IndexBoundsBuilderTest, TranslateElemMatchValueNotEqualToNullShouldBuildInExactBoundsIfIndexIsNotMultiKey) { BSONObj indexPattern = BSON("a" << 1); - IndexEntry testIndex(indexPattern); + auto testIndex = buildSimpleIndexEntry(indexPattern); BSONObj matchObj = BSON("a" << BSON("$elemMatch" << BSON("$ne" << BSONNULL))); unique_ptr<MatchExpression> expr(parseMatchExpression(matchObj)); @@ -2302,7 +2328,7 @@ TEST(IndexBoundsBuilderTest, TEST(IndexBoundsBuilderTest, TranslateNotEqualToStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = BSON("a" << BSON("$ne" @@ -2338,7 +2364,7 @@ TEST(IndexBoundsBuilderTest, TranslateNotEqualToStringWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateEqualToStringElemMatchValueWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$elemMatch: {$eq: 'baz'}}}"); @@ -2359,7 +2385,7 @@ TEST(IndexBoundsBuilderTest, TranslateEqualToStringElemMatchValueWithMockCollato TEST(IndexBoundsBuilderTest, TranslateLTEToStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$lte: 'foo'}}"); @@ -2379,7 +2405,7 @@ TEST(IndexBoundsBuilderTest, TranslateLTEToStringWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateLTEToNumberWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$lte: 3}}"); @@ -2400,7 +2426,7 @@ TEST(IndexBoundsBuilderTest, TranslateLTEToNumberWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateLTStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$lt: 'foo'}}"); @@ -2420,7 +2446,7 @@ TEST(IndexBoundsBuilderTest, TranslateLTStringWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateLTNumberWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$lt: 3}}"); @@ -2441,7 +2467,7 @@ TEST(IndexBoundsBuilderTest, TranslateLTNumberWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateGTStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$gt: 'foo'}}"); @@ -2462,7 +2488,7 @@ TEST(IndexBoundsBuilderTest, TranslateGTStringWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateGTNumberWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$gt: 3}}"); @@ -2483,7 +2509,7 @@ TEST(IndexBoundsBuilderTest, TranslateGTNumberWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateGTEToStringWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$gte: 'foo'}}"); @@ -2503,7 +2529,7 @@ TEST(IndexBoundsBuilderTest, TranslateGTEToStringWithMockCollator) { TEST(IndexBoundsBuilderTest, TranslateGTEToNumberWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$gte: 3}}"); @@ -2524,7 +2550,7 @@ TEST(IndexBoundsBuilderTest, TranslateGTEToNumberWithMockCollator) { TEST(IndexBoundsBuilderTest, SimplePrefixRegexWithMockCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: /^foo/}"); @@ -2546,7 +2572,7 @@ TEST(IndexBoundsBuilderTest, SimplePrefixRegexWithMockCollator) { TEST(IndexBoundsBuilderTest, NotWithMockCollatorIsExact) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$ne: 3}}"); @@ -2567,7 +2593,7 @@ TEST(IndexBoundsBuilderTest, NotWithMockCollatorIsExact) { TEST(IndexBoundsBuilderTest, ExistsTrueWithMockCollatorAndSparseIsExact) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; testIndex.sparse = true; @@ -2588,7 +2614,7 @@ TEST(IndexBoundsBuilderTest, ExistsTrueWithMockCollatorAndSparseIsExact) { TEST(IndexBoundsBuilderTest, ExistsFalseWithMockCollatorIsInexactFetch) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$exists: false}}"); @@ -2608,7 +2634,7 @@ TEST(IndexBoundsBuilderTest, ExistsFalseWithMockCollatorIsInexactFetch) { TEST(IndexBoundsBuilderTest, TypeStringIsInexactFetch) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$type: 'string'}}"); @@ -2628,7 +2654,7 @@ TEST(IndexBoundsBuilderTest, TypeStringIsInexactFetch) { TEST(IndexBoundsBuilderTest, InWithStringAndCollatorIsExact) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$in: ['foo']}}"); @@ -2649,7 +2675,7 @@ TEST(IndexBoundsBuilderTest, InWithStringAndCollatorIsExact) { TEST(IndexBoundsBuilderTest, InWithNumberAndStringAndCollatorIsExact) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$in: [2, 'foo']}}"); @@ -2672,7 +2698,7 @@ TEST(IndexBoundsBuilderTest, InWithNumberAndStringAndCollatorIsExact) { TEST(IndexBoundsBuilderTest, InWithRegexAndCollatorIsInexactFetch) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$in: [/^foo/]}}"); @@ -2694,7 +2720,7 @@ TEST(IndexBoundsBuilderTest, InWithRegexAndCollatorIsInexactFetch) { TEST(IndexBoundsBuilderTest, InWithNumberAndCollatorIsExact) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$in: [2]}}"); @@ -2713,7 +2739,7 @@ TEST(IndexBoundsBuilderTest, InWithNumberAndCollatorIsExact) { TEST(IndexBoundsBuilderTest, LTEMaxKeyWithCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$lte: {$maxKey: 1}}}"); @@ -2733,7 +2759,7 @@ TEST(IndexBoundsBuilderTest, LTEMaxKeyWithCollator) { TEST(IndexBoundsBuilderTest, LTMaxKeyWithCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$lt: {$maxKey: 1}}}"); @@ -2753,7 +2779,7 @@ TEST(IndexBoundsBuilderTest, LTMaxKeyWithCollator) { TEST(IndexBoundsBuilderTest, GTEMinKeyWithCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$gte: {$minKey: 1}}}"); @@ -2773,7 +2799,7 @@ TEST(IndexBoundsBuilderTest, GTEMinKeyWithCollator) { TEST(IndexBoundsBuilderTest, GTMinKeyWithCollator) { CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$gt: {$minKey: 1}}}"); @@ -2795,7 +2821,7 @@ TEST(IndexBoundsBuilderTest, StringEqualityAgainstHashedIndexWithCollatorUsesHas BSONObj keyPattern = fromjson("{a: 'hashed'}"); BSONElement elt = keyPattern.firstElement(); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(keyPattern); + auto testIndex = buildSimpleIndexEntry(keyPattern); testIndex.collator = &collator; BSONObj obj = fromjson("{a: 'foo'}"); @@ -2824,7 +2850,7 @@ TEST(IndexBoundsBuilderTest, EqualityToNumberAgainstHashedIndexWithCollatorUsesH BSONObj keyPattern = fromjson("{a: 'hashed'}"); BSONElement elt = keyPattern.firstElement(); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(keyPattern); + auto testIndex = buildSimpleIndexEntry(keyPattern); testIndex.collator = &collator; BSONObj obj = fromjson("{a: 3}"); @@ -2851,7 +2877,7 @@ TEST(IndexBoundsBuilderTest, InWithStringAgainstHashedIndexWithCollatorUsesHashO BSONObj keyPattern = fromjson("{a: 'hashed'}"); BSONElement elt = keyPattern.firstElement(); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - IndexEntry testIndex = IndexEntry(keyPattern); + auto testIndex = buildSimpleIndexEntry(keyPattern); testIndex.collator = &collator; BSONObj obj = fromjson("{a: {$in: ['foo']}}"); @@ -2877,7 +2903,7 @@ TEST(IndexBoundsBuilderTest, InWithStringAgainstHashedIndexWithCollatorUsesHashO } TEST(IndexBoundsBuilderTest, TypeArrayWithAdditionalTypesHasOpenBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: ['array', 'long']}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -2894,7 +2920,7 @@ TEST(IndexBoundsBuilderTest, TypeArrayWithAdditionalTypesHasOpenBounds) { } TEST(IndexBoundsBuilderTest, TypeStringOrNumberHasCorrectBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: ['string', 'number']}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -2914,7 +2940,7 @@ TEST(IndexBoundsBuilderTest, TypeStringOrNumberHasCorrectBounds) { } TEST(IndexBoundsBuilderTest, RedundantTypeNumberHasCorrectBounds) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: ['number', 'int', 'long', 'double']}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); BSONElement elt = obj.firstElement(); @@ -2932,49 +2958,49 @@ TEST(IndexBoundsBuilderTest, RedundantTypeNumberHasCorrectBounds) { } TEST(IndexBoundsBuilderTest, CanUseCoveredMatchingForEqualityPredicate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$eq: 3}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); ASSERT_TRUE(IndexBoundsBuilder::canUseCoveredMatching(expr.get(), testIndex)); } TEST(IndexBoundsBuilderTest, CannotUseCoveredMatchingForEqualityToArrayPredicate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$eq: [1, 2, 3]}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); ASSERT_FALSE(IndexBoundsBuilder::canUseCoveredMatching(expr.get(), testIndex)); } TEST(IndexBoundsBuilderTest, CannotUseCoveredMatchingForEqualityToNullPredicate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: null}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); ASSERT_FALSE(IndexBoundsBuilder::canUseCoveredMatching(expr.get(), testIndex)); } TEST(IndexBoundsBuilderTest, CannotUseCoveredMatchingForTypeArrayPredicate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$type: 'array'}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); ASSERT_FALSE(IndexBoundsBuilder::canUseCoveredMatching(expr.get(), testIndex)); } TEST(IndexBoundsBuilderTest, CannotUseCoveredMatchingForExistsTruePredicate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$exists: true}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); ASSERT_FALSE(IndexBoundsBuilder::canUseCoveredMatching(expr.get(), testIndex)); } TEST(IndexBoundsBuilderTest, CannotUseCoveredMatchingForExistsFalsePredicate) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); BSONObj obj = fromjson("{a: {$exists: false}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); ASSERT_FALSE(IndexBoundsBuilder::canUseCoveredMatching(expr.get(), testIndex)); } TEST(IndexBoundsBuilderTest, CanUseCoveredMatchingForExistsTrueWithSparseIndex) { - IndexEntry testIndex = IndexEntry(BSONObj()); + auto testIndex = buildSimpleIndexEntry(); testIndex.sparse = true; BSONObj obj = fromjson("{a: {$exists: true}}"); unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); |