diff options
author | coollog <qingyang.chen@gmail.com> | 2015-06-03 14:03:42 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-06-05 17:10:53 -0400 |
commit | a641576b7d811577e28eefc6322e93e3e4a27511 (patch) | |
tree | c05c90742ebad85204f7dd8d029118e092fffa4f /src/mongo/db | |
parent | de6043e0e7bad7a2bf372858658eed91d4dfdabd (diff) | |
download | mongo-a641576b7d811577e28eefc6322e93e3e4a27511.tar.gz |
SERVER-18461 cover range predicates comparing BinData in building index bounds
Closes #973
Signed-off-by: David Storch <david.storch@10gen.com>
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/query/index_bounds_builder.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/query/index_bounds_builder_test.cpp | 72 |
2 files changed, 76 insertions, 4 deletions
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp index 9a5b25affd1..8df448edcf5 100644 --- a/src/mongo/db/query/index_bounds_builder.cpp +++ b/src/mongo/db/query/index_bounds_builder.cpp @@ -383,7 +383,7 @@ namespace mongo { verify(dataObj.isOwned()); oilOut->intervals.push_back(makeRangeInterval(dataObj, typeMatch(dataObj), true)); - if (dataElt.isSimpleType()) { + if (dataElt.isSimpleType() || dataElt.type() == BSONType::BinData) { *tightnessOut = IndexBoundsBuilder::EXACT; } else { @@ -426,7 +426,7 @@ namespace mongo { oilOut->intervals.push_back(interval); } - if (dataElt.isSimpleType()) { + if (dataElt.isSimpleType() || dataElt.type() == BSONType::BinData) { *tightnessOut = IndexBoundsBuilder::EXACT; } else { @@ -468,7 +468,7 @@ namespace mongo { oilOut->intervals.push_back(interval); } - if (dataElt.isSimpleType()) { + if (dataElt.isSimpleType() || dataElt.type() == BSONType::BinData) { *tightnessOut = IndexBoundsBuilder::EXACT; } else { @@ -506,7 +506,7 @@ namespace mongo { verify(dataObj.isOwned()); oilOut->intervals.push_back(makeRangeInterval(dataObj, true, typeMatch(dataObj))); - if (dataElt.isSimpleType()) { + if (dataElt.isSimpleType() || dataElt.type() == BSONType::BinData) { *tightnessOut = IndexBoundsBuilder::EXACT; } else { diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp index 14db9b7a1f1..35bb4304c21 100644 --- a/src/mongo/db/query/index_bounds_builder_test.cpp +++ b/src/mongo/db/query/index_bounds_builder_test.cpp @@ -530,6 +530,78 @@ namespace { ASSERT_EQUALS(tightness, IndexBoundsBuilder::INEXACT_FETCH); } + TEST(IndexBoundsBuilderTest, TranslateLteBinData) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$lte: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA'," + "$type: '00'}}}"); + std::unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + ASSERT_EQ(oil.name, "a"); + ASSERT_EQ(oil.intervals.size(), 1U); + ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( + Interval(fromjson("{'': {$binary: '', $type: '00'}," + "'': {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}"), + true, true))); + ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); + } + + TEST(IndexBoundsBuilderTest, TranslateLtBinData) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$lt: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA'," + "$type: '00'}}}"); + std::unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + ASSERT_EQ(oil.name, "a"); + ASSERT_EQ(oil.intervals.size(), 1U); + ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( + Interval(fromjson("{'': {$binary: '', $type: '00'}," + "'': {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}"), + true, false))); + ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); + } + + TEST(IndexBoundsBuilderTest, TranslateGtBinData) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$gt: {$binary: '////////////////////////////'," + "$type: '00'}}}"); + std::unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + ASSERT_EQ(oil.name, "a"); + ASSERT_EQ(oil.intervals.size(), 1U); + ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( + Interval(fromjson("{'': {$binary: '////////////////////////////', $type: '00'}," + "'': ObjectId('000000000000000000000000')}"), + false, false))); + ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); + } + + TEST(IndexBoundsBuilderTest, TranslateGteBinData) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$gte: {$binary: '////////////////////////////'," + "$type: '00'}}}"); + std::unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + ASSERT_EQ(oil.name, "a"); + ASSERT_EQ(oil.intervals.size(), 1U); + ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( + Interval(fromjson("{'': {$binary: '////////////////////////////', $type: '00'}," + "'': ObjectId('000000000000000000000000')}"), + true, false))); + ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); + } + // // $exists tests // |