summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-05-12 11:52:43 -0700
committerAaron <aaron@10gen.com>2010-05-12 11:52:43 -0700
commit37f2f983a40a9ba6915648ef1e8b55269c24084e (patch)
tree43d8d47efbd61b827ee22400d5982c0b20a87f85 /db
parent322177d9c6b1673707cd4584cbe1c0e799f52aa8 (diff)
downloadmongo-37f2f983a40a9ba6915648ef1e8b55269c24084e.tar.gz
SERVER-109 let query op short stop multi scan planning, handle or in helpers finone
Diffstat (limited to 'db')
-rw-r--r--db/dbhelpers.cpp2
-rw-r--r--db/queryoptimizer.cpp14
-rw-r--r--db/queryoptimizer.h2
3 files changed, 13 insertions, 5 deletions
diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp
index ce798a5122d..27852767f0c 100644
--- a/db/dbhelpers.cpp
+++ b/db/dbhelpers.cpp
@@ -109,7 +109,7 @@ namespace mongo {
}
if ( matcher_->matches( c_->currKey(), c_->currLoc() ) ) {
one_ = c_->current();
- setComplete();
+ setStop();
} else {
c_->advance();
}
diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp
index e104bf7528b..0682aaa06f7 100644
--- a/db/queryoptimizer.cpp
+++ b/db/queryoptimizer.cpp
@@ -258,6 +258,8 @@ namespace mongo {
}
void QueryPlanSet::init() {
+ log() << "query: " << query_ << endl;
+
DEBUGQO( "QueryPlanSet::init " << ns << "\t" << query_ );
plans_.clear();
mayRecordPlan_ = true;
@@ -389,6 +391,7 @@ namespace mongo {
if ( !fbs_.matchPossible() || ( fbs_.nNontrivialRanges() == 0 && order_.isEmpty() ) ||
( !order_.isEmpty() && !strcmp( order_.firstElement().fieldName(), "$natural" ) ) ) {
// Table scan plan
+ log() << "just table scan" << endl;
addPlan( PlanPtr( new QueryPlan( d, -1, fbs_, order_ ) ), checkFirst );
return;
}
@@ -397,6 +400,7 @@ namespace mongo {
PlanSet plans;
for( int i = 0; i < d->nIndexes; ++i ) {
+ log() << "checking index: " << i << endl;
IndexDetails& id = d->idx(i);
const IndexSpec& spec = id.getSpec();
IndexSuitability suitability = HELPFUL;
@@ -555,10 +559,11 @@ namespace mongo {
_ns( ns ),
_or( !query.getField( "$or" ).eoo() ),
_query( query.getOwned() ),
- _i() {
+ _i(),
+ _honorRecordedPlan( honorRecordedPlan ) {
// _fros( ns, query ) {
// eventually implement (some of?) these
- if ( !order.isEmpty() || hint || !honorRecordedPlan || !min.isEmpty() || !max.isEmpty() ) {
+ if ( !order.isEmpty() || hint || !min.isEmpty() || !max.isEmpty() ) {
_or = false;
}
if ( !_or ) {
@@ -569,6 +574,7 @@ namespace mongo {
massert( 13268, "invalid $or spec", e.type() == Array && e.embeddedObject().nFields() > 0 );
_n = e.embeddedObject().nFields();
}
+ log() << "_or: " << _or << endl;
}
shared_ptr< QueryOp > MultiPlanScanner::runOpOnce( QueryOp &op ) {
@@ -577,13 +583,13 @@ namespace mongo {
++_i;
return _currentQps->runOp( op );
}
- _currentQps.reset( new QueryPlanSet( _ns, nextSimpleQuery(), BSONObj() ) );
+ _currentQps.reset( new QueryPlanSet( _ns, nextSimpleQuery(), BSONObj(), 0, _honorRecordedPlan ) );
return _currentQps->runOp( op );
}
shared_ptr< QueryOp > MultiPlanScanner::runOp( QueryOp &op ) {
shared_ptr< QueryOp > ret = runOpOnce( op );
- while( mayRunMore() ) {
+ while( !ret->stopRequested() && mayRunMore() ) {
ret = runOpOnce( *ret );
}
return ret;
diff --git a/db/queryoptimizer.h b/db/queryoptimizer.h
index 5d5120839a7..a272363b1a3 100644
--- a/db/queryoptimizer.h
+++ b/db/queryoptimizer.h
@@ -98,6 +98,7 @@ namespace mongo {
virtual QueryOp *clone() const = 0;
bool complete() const { return _complete; }
bool error() const { return _error; }
+ bool stopRequested() const { return _stopRequested; }
string exceptionMessage() const { return _exceptionMessage; }
const QueryPlan &qp() const { return *_qp; }
// To be called by QueryPlanSet::Runner only.
@@ -268,6 +269,7 @@ namespace mongo {
auto_ptr< QueryPlanSet > _currentQps;
int _i;
int _n;
+ bool _honorRecordedPlan;
};
// NOTE min, max, and keyPattern will be updated to be consistent with the selected index.