mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
rename FieldRangeOrSet to OrRangeGenerator
This commit is contained in:
parent
c8a934caf7
commit
ddd7dd323d
@ -743,14 +743,14 @@ doneCheckOrder:
|
||||
_ns( ns ),
|
||||
_or( !query.getField( "$or" ).eoo() ),
|
||||
_query( query.getOwned() ),
|
||||
_fros( ns, _query ),
|
||||
_org( ns, _query ),
|
||||
_i(),
|
||||
_honorRecordedPlan( honorRecordedPlan ),
|
||||
_bestGuessOnly( bestGuessOnly ),
|
||||
_hint( ( hint && !hint->eoo() ) ? hint->wrap() : BSONObj() ),
|
||||
_mayYield( mayYield ),
|
||||
_tableScanned() {
|
||||
if ( !order.isEmpty() || !min.isEmpty() || !max.isEmpty() || !_fros.getSpecial().empty() ) {
|
||||
if ( !order.isEmpty() || !min.isEmpty() || !max.isEmpty() || !_org.getSpecial().empty() ) {
|
||||
_or = false;
|
||||
}
|
||||
if ( _or && uselessOr( _hint.firstElement() ) ) {
|
||||
@ -775,8 +775,8 @@ doneCheckOrder:
|
||||
return _currentQps->runOp( op );
|
||||
}
|
||||
++_i;
|
||||
auto_ptr<FieldRangeSetPair> frsp( _fros.topFrsp() );
|
||||
auto_ptr<FieldRangeSetPair> originalFrsp( _fros.topFrspOriginal() );
|
||||
auto_ptr<FieldRangeSetPair> frsp( _org.topFrsp() );
|
||||
auto_ptr<FieldRangeSetPair> originalFrsp( _org.topFrspOriginal() );
|
||||
BSONElement hintElt = _hint.firstElement();
|
||||
_currentQps.reset( new QueryPlanSet( _ns, frsp, originalFrsp, _query, BSONObj(), &hintElt, _honorRecordedPlan, BSONObj(), BSONObj(), _bestGuessOnly, _mayYield ) );
|
||||
shared_ptr<QueryOp> ret( _currentQps->runOp( op ) );
|
||||
@ -784,7 +784,7 @@ doneCheckOrder:
|
||||
_tableScanned = true;
|
||||
} else {
|
||||
// If the full table was scanned, don't bother popping the last or clause.
|
||||
_fros.popOrClause( ret->qp().nsd(), ret->qp().idxNo(), ret->qp().indexed() ? ret->qp().indexKey() : BSONObj() );
|
||||
_org.popOrClause( ret->qp().nsd(), ret->qp().idxNo(), ret->qp().indexed() ? ret->qp().indexKey() : BSONObj() );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -807,9 +807,9 @@ doneCheckOrder:
|
||||
if ( !id ) {
|
||||
return true;
|
||||
}
|
||||
return QueryUtilIndexed::uselessOr( _fros, nsd, nsd->idxNo( *id ) );
|
||||
return QueryUtilIndexed::uselessOr( _org, nsd, nsd->idxNo( *id ) );
|
||||
}
|
||||
return QueryUtilIndexed::uselessOr( _fros, nsd, -1 );
|
||||
return QueryUtilIndexed::uselessOr( _org, nsd, -1 );
|
||||
}
|
||||
|
||||
MultiCursor::MultiCursor( const char *ns, const BSONObj &pattern, const BSONObj &order, shared_ptr<CursorOp> op, bool mayYield )
|
||||
@ -1090,8 +1090,8 @@ doneCheckOrder:
|
||||
return make_pair( BSONObj(), 0 );
|
||||
}
|
||||
|
||||
bool QueryUtilIndexed::uselessOr( const FieldRangeOrSet &fros, NamespaceDetails *d, int hintIdx ) {
|
||||
for( list<FieldRangeSetPair>::const_iterator i = fros._originalOrSets.begin(); i != fros._originalOrSets.end(); ++i ) {
|
||||
bool QueryUtilIndexed::uselessOr( const OrRangeGenerator &org, NamespaceDetails *d, int hintIdx ) {
|
||||
for( list<FieldRangeSetPair>::const_iterator i = org._originalOrSets.begin(); i != org._originalOrSets.end(); ++i ) {
|
||||
if ( hintIdx != -1 ) {
|
||||
if ( !indexUseful( *i, d, hintIdx, BSONObj() ) ) {
|
||||
return true;
|
||||
|
@ -321,7 +321,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
/** @return true iff more $or clauses need to be scanned. */
|
||||
bool mayRunMore() const { return _or ? ( !_tableScanned && !_fros.orFinished() ) : _i == 0; }
|
||||
bool mayRunMore() const { return _or ? ( !_tableScanned && !_org.orFinished() ) : _i == 0; }
|
||||
/** @return non-$or version of explain output. */
|
||||
BSONObj oldExplain() const { assertNotOr(); return _currentQps->explain(); }
|
||||
/** @return true iff this is not a $or query and a plan is selected based on previous success of this plan. */
|
||||
@ -341,7 +341,7 @@ namespace mongo {
|
||||
const char * _ns;
|
||||
bool _or;
|
||||
BSONObj _query;
|
||||
FieldRangeOrSet _fros;
|
||||
OrRangeGenerator _org;
|
||||
auto_ptr<QueryPlanSet> _currentQps;
|
||||
int _i;
|
||||
bool _honorRecordedPlan;
|
||||
@ -447,7 +447,7 @@ namespace mongo {
|
||||
static void clearIndexesForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order );
|
||||
/** Return a recorded best index for the single or multi key pattern. */
|
||||
static pair< BSONObj, long long > bestIndexForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order );
|
||||
static bool uselessOr( const FieldRangeOrSet& fros, NamespaceDetails *d, int hintIdx );
|
||||
static bool uselessOr( const OrRangeGenerator& org, NamespaceDetails *d, int hintIdx );
|
||||
};
|
||||
|
||||
} // namespace mongo
|
||||
|
@ -115,7 +115,7 @@ namespace mongo {
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline FieldRangeSetPair *FieldRangeOrSet::topFrsp() const {
|
||||
inline FieldRangeSetPair *OrRangeGenerator::topFrsp() const {
|
||||
FieldRangeSetPair *ret = new FieldRangeSetPair( _baseSet );
|
||||
if (_orSets.size()) {
|
||||
*ret &= _orSets.front();
|
||||
@ -123,7 +123,7 @@ namespace mongo {
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline FieldRangeSetPair *FieldRangeOrSet::topFrspOriginal() const {
|
||||
inline FieldRangeSetPair *OrRangeGenerator::topFrspOriginal() const {
|
||||
FieldRangeSetPair *ret = new FieldRangeSetPair( _baseSet );
|
||||
if (_originalOrSets.size()) {
|
||||
*ret &= _originalOrSets.front();
|
||||
|
@ -1322,7 +1322,7 @@ namespace mongo {
|
||||
return b.obj();
|
||||
}
|
||||
|
||||
FieldRangeOrSet::FieldRangeOrSet( const char *ns, const BSONObj &query , bool optimize )
|
||||
OrRangeGenerator::OrRangeGenerator( const char *ns, const BSONObj &query , bool optimize )
|
||||
: _baseSet( ns, query, optimize ), _orFound() {
|
||||
|
||||
BSONObjIterator i( _baseSet.originalQuery() );
|
||||
@ -1345,11 +1345,11 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
|
||||
void FieldRangeOrSet::assertMayPopOrClause() {
|
||||
void OrRangeGenerator::assertMayPopOrClause() {
|
||||
massert( 13274, "no or clause to pop", !orFinished() );
|
||||
}
|
||||
|
||||
void FieldRangeOrSet::popOrClause( NamespaceDetails *nsd, int idxNo, const BSONObj &keyPattern ) {
|
||||
void OrRangeGenerator::popOrClause( NamespaceDetails *nsd, int idxNo, const BSONObj &keyPattern ) {
|
||||
assertMayPopOrClause();
|
||||
auto_ptr<FieldRangeSet> holder;
|
||||
const FieldRangeSet *toDiff = &_originalOrSets.front().frsForIndex( nsd, idxNo );
|
||||
@ -1361,7 +1361,7 @@ namespace mongo {
|
||||
popOrClause( toDiff, nsd, idxNo, keyPattern );
|
||||
}
|
||||
|
||||
void FieldRangeOrSet::popOrClauseSingleKey() {
|
||||
void OrRangeGenerator::popOrClauseSingleKey() {
|
||||
assertMayPopOrClause();
|
||||
FieldRangeSet *toDiff = &_originalOrSets.front()._singleKey;
|
||||
popOrClause( toDiff );
|
||||
@ -1377,7 +1377,7 @@ namespace mongo {
|
||||
* empty we do not constrain the previous clause's ranges using index keys,
|
||||
* which may reduce opportunities for range elimination.
|
||||
*/
|
||||
void FieldRangeOrSet::popOrClause( const FieldRangeSet *toDiff, NamespaceDetails *d, int idxNo, const BSONObj &keyPattern ) {
|
||||
void OrRangeGenerator::popOrClause( const FieldRangeSet *toDiff, NamespaceDetails *d, int idxNo, const BSONObj &keyPattern ) {
|
||||
list<FieldRangeSetPair>::iterator i = _orSets.begin();
|
||||
list<FieldRangeSetPair>::iterator j = _originalOrSets.begin();
|
||||
++i;
|
||||
|
@ -130,7 +130,7 @@ namespace mongo {
|
||||
*/
|
||||
class FieldRangeSet {
|
||||
public:
|
||||
friend class FieldRangeOrSet;
|
||||
friend class OrRangeGenerator;
|
||||
friend class FieldRangeVector;
|
||||
FieldRangeSet( const char *ns, const BSONObj &query , bool singleKey , bool optimize=true );
|
||||
|
||||
@ -277,7 +277,7 @@ namespace mongo {
|
||||
BSONObj simplifiedQueryForIndex( NamespaceDetails *d, int idxNo, const BSONObj &keyPattern ) const;
|
||||
FieldRangeSet _singleKey;
|
||||
FieldRangeSet _multiKey;
|
||||
friend class FieldRangeOrSet;
|
||||
friend class OrRangeGenerator;
|
||||
friend struct QueryUtilIndexed;
|
||||
};
|
||||
|
||||
@ -373,9 +373,9 @@ namespace mongo {
|
||||
* for the current $or clause, in some cases by excluding ranges that were
|
||||
* included in a previous clause.
|
||||
*/
|
||||
class FieldRangeOrSet {
|
||||
class OrRangeGenerator {
|
||||
public:
|
||||
FieldRangeOrSet( const char *ns, const BSONObj &query , bool optimize=true );
|
||||
OrRangeGenerator( const char *ns, const BSONObj &query , bool optimize=true );
|
||||
|
||||
/**
|
||||
* @return true iff we are done scanning $or clauses. if there's a
|
||||
|
12
s/chunk.cpp
12
s/chunk.cpp
@ -728,9 +728,9 @@ namespace mongo {
|
||||
rwlock lk( _lock , false );
|
||||
|
||||
//TODO look into FieldRangeSetOr
|
||||
FieldRangeOrSet fros(_ns.c_str(), query, false);
|
||||
OrRangeGenerator org(_ns.c_str(), query, false);
|
||||
|
||||
const string special = fros.getSpecial();
|
||||
const string special = org.getSpecial();
|
||||
if (special == "2d") {
|
||||
BSONForEach(field, query) {
|
||||
if (getGtLtOp(field) == BSONObj::opNEAR) {
|
||||
@ -745,7 +745,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
do {
|
||||
boost::scoped_ptr<FieldRangeSetPair> frsp (fros.topFrsp());
|
||||
boost::scoped_ptr<FieldRangeSetPair> frsp (org.topFrsp());
|
||||
{
|
||||
// special case if most-significant field isn't in query
|
||||
FieldRange range = frsp->singleKeyRange(_key.key().firstElement().fieldName());
|
||||
@ -780,11 +780,11 @@ namespace mongo {
|
||||
//return;
|
||||
}
|
||||
|
||||
if (fros.moreOrClauses())
|
||||
fros.popOrClauseSingleKey();
|
||||
if (org.moreOrClauses())
|
||||
org.popOrClauseSingleKey();
|
||||
|
||||
}
|
||||
while (fros.moreOrClauses());
|
||||
while (org.moreOrClauses());
|
||||
}
|
||||
|
||||
void ChunkManager::getShardsForRange(set<Shard>& shards, const BSONObj& min, const BSONObj& max) {
|
||||
|
Loading…
Reference in New Issue
Block a user