From c8e0f33f3f1ef54cfd9fd358dcba3798de700ef0 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 8 Jun 2010 12:29:30 -0700 Subject: [PATCH] compile sharding --- db/queryoptimizer.cpp | 24 ++++++++++++++++++++++-- db/queryoptimizer.h | 1 + db/queryutil.cpp | 18 ------------------ db/queryutil.h | 6 +++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp index a403713af3a..3fc32204691 100644 --- a/db/queryoptimizer.cpp +++ b/db/queryoptimizer.cpp @@ -593,7 +593,7 @@ namespace mongo { if ( !order.isEmpty() || ( hint && !hint->eoo() ) || !min.isEmpty() || !max.isEmpty() || !_fros.getSpecial().empty() ) { _or = false; } - if ( _or && _fros.uselessOr() ) { + if ( _or && uselessOr() ) { _or = false; } // if _or == false, don't use or clauses for index selection @@ -630,7 +630,27 @@ namespace mongo { ret = runOpOnce( *ret ); } return ret; - } + } + + bool MultiPlanScanner::uselessOr() const { + vector< BSONObj > ret; + _fros.allClausesSimplified( ret ); + for( vector< BSONObj >::const_iterator i = ret.begin(); i != ret.end(); ++i ) { + bool useful = false; + NamespaceDetails::IndexIterator j = nsdetails( _ns )->ii(); + while( j.more() ) { + IndexDetails &id = j.next(); + if ( id.getSpec().suitability( *i, BSONObj() ) != USELESS ) { + useful = true; + break; + } + } + if ( !useful ) { + return true; + } + } + return false; + } bool indexWorks( const BSONObj &idxPattern, const BSONObj &sampleKey, int direction, int firstSignificantField ) { BSONObjIterator p( idxPattern ); diff --git a/db/queryoptimizer.h b/db/queryoptimizer.h index f4413335642..9964fbd7767 100644 --- a/db/queryoptimizer.h +++ b/db/queryoptimizer.h @@ -274,6 +274,7 @@ namespace mongo { void assertNotOr() const { massert( 13266, "not implemented for $or query", !_or ); } + bool uselessOr() const; const char * _ns; bool _or; BSONObj _query; diff --git a/db/queryutil.cpp b/db/queryutil.cpp index 385bfa98817..90d69789d07 100644 --- a/db/queryutil.cpp +++ b/db/queryutil.cpp @@ -621,24 +621,6 @@ namespace mongo { } } - bool FieldRangeOrSet::uselessOr() const { - for( list< FieldRangeSet >::const_iterator i = _orSets.begin(); i != _orSets.end(); ++i ) { - bool useful = false; - NamespaceDetails::IndexIterator j = nsdetails( _baseSet.ns() )->ii(); - while( j.more() ) { - IndexDetails &id = j.next(); - if ( id.getSpec().suitability( i->simplifiedQuery(), BSONObj() ) != USELESS ) { - useful = true; - break; - } - } - if ( !useful ) { - return true; - } - } - return false; - } - FieldRange *FieldRangeSet::trivialRange_ = 0; FieldRange &FieldRangeSet::trivialRange() { if ( trivialRange_ == 0 ) diff --git a/db/queryutil.h b/db/queryutil.h index c980824de4e..b36cf8e1e76 100644 --- a/db/queryutil.h +++ b/db/queryutil.h @@ -244,7 +244,6 @@ namespace mongo { public: FieldRangeOrSet( const char *ns, const BSONObj &query , bool optimize=true ); // if there's a useless or clause, we won't use or ranges to help with scanning - bool uselessOr() const; bool orFinished() const { return _orFound && _orSets.empty(); } // removes first or clause, and removes the field ranges it covers from all subsequent or clauses // this could invalidate the result of the last topFrs() @@ -269,6 +268,11 @@ namespace mongo { *ret &= _orSets.front(); return ret; } + void allClausesSimplified( vector< BSONObj > &ret ) const { + for( list< FieldRangeSet >::const_iterator i = _orSets.begin(); i != _orSets.end(); ++i ) { + ret.push_back( i->simplifiedQuery() ); + } + } string getSpecial() const { return _baseSet.getSpecial(); } private: FieldRangeSet _baseSet;