diff options
author | Judah Schvimer <judah@mongodb.com> | 2016-09-15 10:20:59 -0400 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2016-09-15 10:20:59 -0400 |
commit | 4dc41d135737dbda0a9ecc70af75687dd5df9099 (patch) | |
tree | 381dcdf024db4da65d20051a430a4f7515c122d6 /src/mongo/db/query/query_solution.cpp | |
parent | 97dd4a8eebfb2a2dc2e3a5e0907c8fc6e859c0ac (diff) | |
download | mongo-4dc41d135737dbda0a9ecc70af75687dd5df9099.tar.gz |
SERVER-26033 Allow simple range to exclude start key
Diffstat (limited to 'src/mongo/db/query/query_solution.cpp')
-rw-r--r-- | src/mongo/db/query/query_solution.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/mongo/db/query/query_solution.cpp b/src/mongo/db/query/query_solution.cpp index ed9ab70b4cc..aa2426954c4 100644 --- a/src/mongo/db/query/query_solution.cpp +++ b/src/mongo/db/query/query_solution.cpp @@ -52,31 +52,33 @@ OrderedIntervalList buildStringBoundsOil(const std::string& keyName) { BSONObjBuilder strBob; strBob.appendMinForType("", BSONType::String); strBob.appendMaxForType("", BSONType::String); - ret.intervals.push_back(IndexBoundsBuilder::makeRangeInterval(strBob.obj(), true, false)); + ret.intervals.push_back( + IndexBoundsBuilder::makeRangeInterval(strBob.obj(), BoundInclusion::kIncludeStartKeyOnly)); BSONObjBuilder objBob; objBob.appendMinForType("", BSONType::Object); objBob.appendMaxForType("", BSONType::Object); - ret.intervals.push_back(IndexBoundsBuilder::makeRangeInterval(objBob.obj(), true, false)); + ret.intervals.push_back( + IndexBoundsBuilder::makeRangeInterval(objBob.obj(), BoundInclusion::kIncludeStartKeyOnly)); BSONObjBuilder arrBob; arrBob.appendMinForType("", BSONType::Array); arrBob.appendMaxForType("", BSONType::Array); - ret.intervals.push_back(IndexBoundsBuilder::makeRangeInterval(arrBob.obj(), true, false)); + ret.intervals.push_back( + IndexBoundsBuilder::makeRangeInterval(arrBob.obj(), BoundInclusion::kIncludeStartKeyOnly)); return ret; } bool rangeCanContainString(const BSONElement& startKey, const BSONElement& endKey, - bool endKeyInclusive) { + BoundInclusion boundInclusion) { OrderedIntervalList stringBoundsOil = buildStringBoundsOil(""); OrderedIntervalList rangeOil; BSONObjBuilder bob; bob.appendAs(startKey, ""); bob.appendAs(endKey, ""); - rangeOil.intervals.push_back( - IndexBoundsBuilder::makeRangeInterval(bob.obj(), true, endKeyInclusive)); + rangeOil.intervals.push_back(IndexBoundsBuilder::makeRangeInterval(bob.obj(), boundInclusion)); IndexBoundsBuilder::intersectize(rangeOil, &stringBoundsOil); return !stringBoundsOil.intervals.empty(); @@ -606,8 +608,11 @@ std::set<StringData> IndexScanNode::getFieldsWithStringBounds(const IndexBounds& BSONElement endKey = endKeyIterator.next(); if (SimpleBSONElementComparator::kInstance.evaluate(startKey != endKey) || CollationIndexKey::isCollatableType(startKey.type())) { - if (!rangeCanContainString( - startKey, endKey, (startKeyIterator.more() || bounds.endKeyInclusive))) { + BoundInclusion boundInclusion = bounds.boundInclusion; + if (startKeyIterator.more()) { + boundInclusion = BoundInclusion::kIncludeBothStartAndEndKeys; + } + if (!rangeCanContainString(startKey, endKey, boundInclusion)) { // If the first non-point range cannot contain strings, we don't need to // add it to the return set. keyPatternIterator.next(); |