summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorcoollog <qingyang.chen@gmail.com>2015-06-03 14:03:42 -0400
committerDavid Storch <david.storch@10gen.com>2015-06-05 17:10:53 -0400
commita641576b7d811577e28eefc6322e93e3e4a27511 (patch)
treec05c90742ebad85204f7dd8d029118e092fffa4f /src/mongo/db
parentde6043e0e7bad7a2bf372858658eed91d4dfdabd (diff)
downloadmongo-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.cpp8
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp72
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
//