summaryrefslogtreecommitdiff
path: root/src/mongo/db/keypattern.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2014-05-01 16:19:01 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2014-05-05 18:15:47 -0400
commit9ba412717035fa34502c89e5886fa3a3ae3e05d5 (patch)
tree865a784a4cc7f6e683776a609a21c720e03f8402 /src/mongo/db/keypattern.cpp
parent9aeb3d4c5a70f8fb3616c5aea22c15db86b0d6e1 (diff)
downloadmongo-9ba412717035fa34502c89e5886fa3a3ae3e05d5.tar.gz
SERVER-13807 Remove old query framework related to shard targeting
Diffstat (limited to 'src/mongo/db/keypattern.cpp')
-rw-r--r--src/mongo/db/keypattern.cpp125
1 files changed, 0 insertions, 125 deletions
diff --git a/src/mongo/db/keypattern.cpp b/src/mongo/db/keypattern.cpp
index ecd44b448c4..222253e4c4d 100644
--- a/src/mongo/db/keypattern.cpp
+++ b/src/mongo/db/keypattern.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/keypattern.h"
#include "mongo/db/hasher.h"
-#include "mongo/db/queryutil.h"
#include "mongo/util/mongoutils/str.h"
using namespace mongoutils;
@@ -136,87 +135,6 @@ namespace mongo {
return newBound.obj();
}
- typedef vector<pair<BSONObj,BSONObj> >::const_iterator BoundListIter;
-
- BoundList KeyPattern::keyBounds( const FieldRangeSet& queryConstraints ) const {
- // To construct our bounds we will generate intervals based on constraints for
- // the first field, then compound intervals based on constraints for the first
- // 2 fields, then compound intervals for the first 3 fields, etc.
- // As we loop through the fields, we start generating new intervals that will later
- // get extended in another iteration of the loop. We define these partially constructed
- // intervals using pairs of BSONObjBuilders (shared_ptrs, since after one iteration of the
- // loop they still must exist outside their scope).
- typedef vector< pair< shared_ptr<BSONObjBuilder> ,
- shared_ptr<BSONObjBuilder> > > BoundBuilders;
- BoundBuilders builders;
- builders.push_back( make_pair( shared_ptr<BSONObjBuilder>( new BSONObjBuilder() ),
- shared_ptr<BSONObjBuilder>( new BSONObjBuilder() ) ) );
- BSONObjIterator i( _pattern );
- // until equalityOnly is false, we are just dealing with equality (no range or $in queries).
- bool equalityOnly = true;
- while( i.more() ) {
- BSONElement e = i.next();
-
- // get the relevant intervals for this field, but we may have to transform the
- // list of what's relevant according to the expression for this field
- const FieldRange &fr = queryConstraints.range( e.fieldName() );
- const vector<FieldInterval> &oldIntervals = fr.intervals();
- BoundList fieldBounds = _transformFieldBounds( oldIntervals , e );
-
- if ( equalityOnly ) {
- if ( fieldBounds.size() == 1 &&
- ( fieldBounds.front().first == fieldBounds.front().second ) ){
- // this field is only a single point-interval
- BoundBuilders::const_iterator j;
- for( j = builders.begin(); j != builders.end(); ++j ) {
- j->first->appendElements( fieldBounds.front().first );
- j->second->appendElements( fieldBounds.front().first );
- }
- }
- else {
- // This clause is the first to generate more than a single point.
- // We only execute this clause once. After that, we simplify the bound
- // extensions to prevent combinatorial explosion.
- equalityOnly = false;
-
- BoundBuilders newBuilders;
- BoundBuilders::const_iterator i;
- for( i = builders.begin(); i != builders.end(); ++i ) {
- BSONObj first = i->first->obj();
- BSONObj second = i->second->obj();
-
- for(BoundListIter j = fieldBounds.begin(); j != fieldBounds.end(); ++j ) {
- uassert( 16452,
- "combinatorial limit of $in partitioning of results exceeded" ,
- newBuilders.size() < MAX_IN_COMBINATIONS );
- newBuilders.push_back(
- make_pair( shared_ptr<BSONObjBuilder>( new BSONObjBuilder() ),
- shared_ptr<BSONObjBuilder>( new BSONObjBuilder())));
- newBuilders.back().first->appendElements( first );
- newBuilders.back().second->appendElements( second );
- newBuilders.back().first->appendElements( j->first );
- newBuilders.back().second->appendElements( j->second );
- }
- }
- builders = newBuilders;
- }
- }
- else {
- // if we've already generated a range or multiple point-intervals
- // just extend what we've generated with min/max bounds for this field
- BoundBuilders::const_iterator j;
- for( j = builders.begin(); j != builders.end(); ++j ) {
- j->first->appendElements( fieldBounds.front().first );
- j->second->appendElements( fieldBounds.back().second );
- }
- }
- }
- BoundList ret;
- for( BoundBuilders::const_iterator i = builders.begin(); i != builders.end(); ++i )
- ret.push_back( make_pair( i->first->obj(), i->second->obj() ) );
- return ret;
- }
-
BoundList KeyPattern::keyBounds( const BSONObj& keyPattern, const IndexBounds& indexBounds ) {
invariant(indexBounds.fields.size() == (size_t)keyPattern.nFields());
@@ -308,47 +226,4 @@ namespace mongo {
return ret;
}
- BoundList KeyPattern::_transformFieldBounds( const vector<FieldInterval>& oldIntervals ,
- const BSONElement& field ) const {
-
- BoundList ret;
- vector<FieldInterval>::const_iterator i;
- for( i = oldIntervals.begin(); i != oldIntervals.end(); ++i ) {
- if ( isAscending( field ) ){
- // straightforward map [a,b] --> [a,b]
- ret.push_back( make_pair( BSON( field.fieldName() << i->_lower._bound ) ,
- BSON( field.fieldName() << i->_upper._bound ) ) );
- } else if ( isDescending( field ) ) {
- // reverse [a,b] --> [b,a]
- ret.push_back( make_pair( BSON( field.fieldName() << i->_upper._bound ) ,
- BSON( field.fieldName() << i->_lower._bound ) ) );
- } else if ( isHashed( field ) ){
- if ( i->equality() ) {
- // hash [a,a] --> [hash(a),hash(a)]
- long long int h = BSONElementHasher::hash64( i->_lower._bound ,
- BSONElementHasher::DEFAULT_HASH_SEED );
- ret.push_back( make_pair( BSON( field.fieldName() << h ) ,
- BSON( field.fieldName() << h ) ) );
- } else {
- // if it's a range interval and this field is hashed, just generate one
- // big interval from MinKey to MaxKey, since these vals could lie anywhere
- ret.clear();
- ret.push_back( make_pair( BSON( field.fieldName() << MINKEY ) ,
- BSON( field.fieldName() << MAXKEY ) ) );
- break;
- }
- }
- }
-
- if ( isDescending( field ) ) {
- // now order is [ [2,1], [4,3] , [6,5]....[n,n-1] ]. Reverse to get decreasing order.
- reverse( ret.begin() , ret.end() );
- } else if ( isHashed( field ) ){
- // [ hash(a) , hash(b) , hash(c) ...] no longer in order, so sort before returning
- sort( ret.begin() , ret.end() );
- }
-
- return ret;
- }
-
} // namespace mongo