summaryrefslogtreecommitdiff
path: root/db/queryoptimizer.cpp
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-06-05 19:50:34 +0200
committerAntonin Kral <a.kral@bobek.cz>2012-06-05 19:50:34 +0200
commit3703a282eca7e79e91f4bd651b1b861b76dc6c68 (patch)
treeb69552c69c48ebc6899f7bbbe42843793a423237 /db/queryoptimizer.cpp
parent61619b3142c1de8f60f91964ff2656054d4f11a6 (diff)
downloadmongodb-3703a282eca7e79e91f4bd651b1b861b76dc6c68.tar.gz
Imported Upstream version 2.0.6
Diffstat (limited to 'db/queryoptimizer.cpp')
-rw-r--r--db/queryoptimizer.cpp51
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 ) {