diff options
author | Antonin Kral <a.kral@bobek.cz> | 2012-06-05 19:50:36 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2012-06-05 19:50:36 +0200 |
commit | 291c9687fb2307dc22d1f269eb4d0aa98fe8cadc (patch) | |
tree | f46fac7bf8530d100aa55da89dfaa53490fbb350 /db/queryoptimizer.cpp | |
parent | 6d0f215499dda50fdba4a6f60ab359efe0054e0d (diff) | |
parent | 3703a282eca7e79e91f4bd651b1b861b76dc6c68 (diff) | |
download | mongodb-291c9687fb2307dc22d1f269eb4d0aa98fe8cadc.tar.gz |
Merge tag 'upstream/2.0.6'
Upstream version 2.0.6
Diffstat (limited to 'db/queryoptimizer.cpp')
-rw-r--r-- | db/queryoptimizer.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp index 71ca657..8ec4cb4 100644 --- a/db/queryoptimizer.cpp +++ b/db/queryoptimizer.cpp @@ -214,22 +214,6 @@ doneCheckOrder: if ( willScanTable() ) { if ( _frs.nNontrivialRanges() ) { checkTableScanAllowed( _frs.ns() ); - - // if we are doing a table scan on _id - // and its a capped collection - // we disallow as its a common user error - // .system. and local collections are exempt - if ( _d && _d->capped && _frs.range( "_id" ).nontrivial() ) { - if ( cc().isSyncThread() || - str::contains( _frs.ns() , ".system." ) || - str::startsWith( _frs.ns() , "local." ) ) { - // ok - } - else { - warning() << "_id query on capped collection without an _id index, performance will be poor collection: " << _frs.ns() << endl; - //uassert( 14820, str::stream() << "doing _id query on a capped collection without an index is not allowed: " << _frs.ns() , - } - } } return findTableScan( _frs.ns(), _order, startLoc ); } @@ -486,12 +470,14 @@ doneCheckOrder: _usingPrerecordedPlan = true; _mayRecordPlan = false; _plans.push_back( p ); + warnOnCappedIdTableScan(); return; } } } addOtherPlans( false ); + warnOnCappedIdTableScan(); } void QueryPlanSet::addOtherPlans( bool checkFirst ) { @@ -633,6 +619,31 @@ doneCheckOrder: } return _plans[0]; } + + void QueryPlanSet::warnOnCappedIdTableScan() const { + // if we are doing a table scan on _id + // and it's a capped collection + // we warn as it's a common user error + // .system. and local collections are exempt + const char *ns = _frsp->ns(); + NamespaceDetails *d = nsdetails( ns ); + if ( d && + d->capped && + nPlans() == 1 && + firstPlan()->willScanTable() && + firstPlan()->multikeyFrs().range( "_id" ).nontrivial() ) { + if ( cc().isSyncThread() || + str::contains( ns , ".system." ) || + str::startsWith( ns , "local." ) ) { + // ok + } + else { + warning() + << "unindexed _id query on capped collection, " + << "performance will be poor collection: " << ns << endl; + } + } + } QueryPlanSet::Runner::Runner( QueryPlanSet &plans, QueryOp &op ) : _op( op ), @@ -1247,8 +1258,12 @@ doneCheckOrder: void QueryUtilIndexed::clearIndexesForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order ) { SimpleMutex::scoped_lock lk(NamespaceDetailsTransient::_qcMutex); NamespaceDetailsTransient& nsd = NamespaceDetailsTransient::get_inlock( frsp.ns() ); - nsd.registerIndexForPattern( frsp._singleKey.pattern( order ), BSONObj(), 0 ); - nsd.registerIndexForPattern( frsp._multiKey.pattern( order ), BSONObj(), 0 ); + if ( frsp._singleKey.matchPossible() ) { + nsd.registerIndexForPattern( frsp._singleKey.pattern( order ), BSONObj(), 0 ); + } + if ( frsp._multiKey.matchPossible() ) { + nsd.registerIndexForPattern( frsp._multiKey.pattern( order ), BSONObj(), 0 ); + } } pair< BSONObj, long long > QueryUtilIndexed::bestIndexForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order ) { |