diff options
author | Ian Boros <ian.boros@10gen.com> | 2018-07-02 18:44:05 -0400 |
---|---|---|
committer | Ian Boros <ian.boros@10gen.com> | 2018-07-31 13:33:34 -0400 |
commit | 7f442763c791873d74bea5c0c6e01812933deb38 (patch) | |
tree | f6872777be64613465e89c5826301293db639cc7 /src/mongo/db/query/index_bounds_test.cpp | |
parent | 21c25ecaaaabe6ad4d7e8a2eb261dad1e2eb90df (diff) | |
download | mongo-7f442763c791873d74bea5c0c6e01812933deb38.tar.gz |
SERVER-34846 Forwardize IndexBounds before intersectizing their OILs
Diffstat (limited to 'src/mongo/db/query/index_bounds_test.cpp')
-rw-r--r-- | src/mongo/db/query/index_bounds_test.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/mongo/db/query/index_bounds_test.cpp b/src/mongo/db/query/index_bounds_test.cpp index 72343489928..40fddf64e66 100644 --- a/src/mongo/db/query/index_bounds_test.cpp +++ b/src/mongo/db/query/index_bounds_test.cpp @@ -122,6 +122,58 @@ TEST(IndexBoundsTest, ValidOverlapOnlyWhenBothOpen) { ASSERT(bounds.isValidFor(BSON("foo" << 1), 1)); } +TEST(IndexBoundsCheckerTest, CheckOILReverse) { + // Check that the reverse of an empty list is empty. + OrderedIntervalList emptyList("someField"); + emptyList.reverse(); + OrderedIntervalList expectedReversedEmptyList("someField"); + ASSERT_TRUE(emptyList == expectedReversedEmptyList); + + // The reverse of a single-interval OIL is just an OIL with that interval reversed. + OrderedIntervalList singleEltList("xyz"); + singleEltList.intervals = {Interval(BSON("" << 5 << "" << 0), false, false)}; + singleEltList.reverse(); + + OrderedIntervalList expectedReversedSingleEltList("xyz"); + expectedReversedSingleEltList.intervals = {Interval(BSON("" << 0 << "" << 5), false, false)}; + ASSERT_TRUE(singleEltList == expectedReversedSingleEltList); + + // List with a few elements + OrderedIntervalList fooList("foo"); + fooList.intervals = {Interval(BSON("" << 40 << "" << 35), false, true), + Interval(BSON("" << 30 << "" << 21), true, true), + Interval(BSON("" << 20 << "" << 7), true, false)}; + fooList.reverse(); + + OrderedIntervalList expectedReverseFooList("foo"); + expectedReverseFooList.intervals = {Interval(BSON("" << 7 << "" << 20), false, true), + Interval(BSON("" << 21 << "" << 30), true, true), + Interval(BSON("" << 35 << "" << 40), true, false)}; + + ASSERT_TRUE(fooList == expectedReverseFooList); +} + +TEST(IndexBoundsTest, OILReverseClone) { + OrderedIntervalList emptyA("foo"); + OrderedIntervalList emptyB = emptyA.reverseClone(); + + ASSERT(emptyA == emptyB); + ASSERT(emptyA.computeDirection() == Interval::Direction::kDirectionNone); + ASSERT(emptyB.computeDirection() == Interval::Direction::kDirectionNone); + + OrderedIntervalList list("foo"); + + list.intervals.push_back(Interval(BSON("" << 7 << "" << 20), true, false)); + list.intervals.push_back(Interval(BSON("" << 20 << "" << 25), false, true)); + + OrderedIntervalList listClone = list.reverseClone(); + OrderedIntervalList reverseList("foo"); + reverseList.intervals = {Interval(BSON("" << 25 << "" << 20), true, false), + Interval(BSON("" << 20 << "" << 7), false, true)}; + ASSERT(reverseList == listClone); + ASSERT(listClone.computeDirection() == Interval::Direction::kDirectionDescending); +} + // // Tests for OrderedIntervalList::complement() // @@ -519,6 +571,47 @@ TEST(IndexBoundsTest, SimpleRangeBoundsNotEqualDifferentEndKeyInclusive) { ASSERT_TRUE(bounds1 != bounds2); } +TEST(IndexBoundsTest, ForwardizeSimpleRange) { + IndexBounds bounds1; + bounds1.isSimpleRange = true; + bounds1.startKey = BSON("" << 2 << "" << 4); + bounds1.endKey = BSON("" << 1 << "" << 3); + bounds1.boundInclusion = BoundInclusion::kIncludeStartKeyOnly; + + IndexBounds expectedBounds1; + expectedBounds1.isSimpleRange = true; + expectedBounds1.startKey = bounds1.endKey; + expectedBounds1.endKey = bounds1.startKey; + expectedBounds1.boundInclusion = BoundInclusion::kIncludeEndKeyOnly; + ASSERT(bounds1.forwardize() == expectedBounds1); + + IndexBounds bounds2; + bounds1.isSimpleRange = true; + bounds1.startKey = BSON("" << 1 << "" << 3); + bounds1.endKey = BSON("" << 2 << "" << 4); + bounds1.boundInclusion = BoundInclusion::kIncludeStartKeyOnly; + ASSERT(bounds2 == bounds2.forwardize()); +} + + +TEST(IndexBoundsTest, ForwardizeOnNonSimpleRangeShouldOnlyReverseDescendingRanges) { + OrderedIntervalList fooList("foo"); + fooList.intervals = {Interval(BSON("" << 7 << "" << 20), true, true)}; + + OrderedIntervalList barList("bar"); + barList.intervals = {Interval(BSON("" << 10 << "" << 5), false, false), + Interval(BSON("" << 4 << "" << 3), false, false)}; + + IndexBounds bounds; + bounds.fields = {fooList, barList}; + + IndexBounds forwardizedBounds = bounds.forwardize(); + + IndexBounds expectedBounds; + expectedBounds.fields = {fooList, barList.reverseClone()}; + ASSERT(expectedBounds == forwardizedBounds); +} + // // Iteration over // |