0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Merge branch 'master' of git@github.com:mongodb/mongo

This commit is contained in:
Dwight 2009-02-26 11:31:25 -05:00
commit 7575ede757
3 changed files with 45 additions and 40 deletions

View File

@ -229,17 +229,14 @@ namespace mongo {
NamespaceDetails *d = nsdetails( ns );
if ( !d )
return;
// Table scan plan
addPlan( PlanPtr( new QueryPlan( fbs_, order_ ) ), checkFirst );
// If table scan is optimal
if ( fbs_.nNontrivialBounds() == 0 && order_.isEmpty() )
return;
// Only table scan can give natural order.
if ( !order_.isEmpty() && !strcmp( order_.firstElement().fieldName(), "$natural" ) )
// If table scan is optimal or natural order requested
if ( ( fbs_.nNontrivialBounds() == 0 && order_.isEmpty() ) ||
( !order_.isEmpty() && !strcmp( order_.firstElement().fieldName(), "$natural" ) ) ) {
// Table scan plan
addPlan( PlanPtr( new QueryPlan( fbs_, order_ ) ), checkFirst );
return;
}
PlanSet plans;
for( int i = 0; i < d->nIndexes; ++i ) {
@ -253,6 +250,9 @@ namespace mongo {
}
for( PlanSet::iterator i = plans.begin(); i != plans.end(); ++i )
addPlan( *i, checkFirst );
// Table scan plan
addPlan( PlanPtr( new QueryPlan( fbs_, order_ ) ), checkFirst );
}
shared_ptr< QueryOp > QueryPlanSet::runOp( QueryOp &op ) {
@ -285,15 +285,8 @@ namespace mongo {
}
for( vector< shared_ptr< QueryOp > >::iterator i = ops.begin(); i != ops.end(); ++i ) {
QueryOp &op = **i;
try {
op.init();
} catch ( const std::exception &e ) {
op.setExceptionMessage( e.what() );
} catch ( ... ) {
op.setExceptionMessage( "Caught unknown exception" );
}
if ( op.complete() )
initOp( **i );
if ( (*i)->complete() )
return *i;
}
@ -303,14 +296,7 @@ namespace mongo {
unsigned errCount = 0;
for( vector< shared_ptr< QueryOp > >::iterator i = ops.begin(); i != ops.end(); ++i ) {
QueryOp &op = **i;
try {
if ( !op.error() )
op.next();
} catch ( const std::exception &e ) {
op.setExceptionMessage( e.what() );
} catch ( ... ) {
op.setExceptionMessage( "Caught unknown exception" );
}
nextOp( op );
if ( op.complete() ) {
if ( plans_.mayRecordPlan_ && op.mayRecordPlan() )
op.qp().registerSelf( nScanned );
@ -329,13 +315,7 @@ namespace mongo {
shared_ptr< QueryOp > op( op_.clone() );
op->setQueryPlan( i->get() );
ops.push_back( op );
try {
op->init();
} catch ( const std::exception &e ) {
op->setExceptionMessage( e.what() );
} catch ( ... ) {
op->setExceptionMessage( "Caught unknown exception" );
}
initOp( *op );
if ( op->complete() )
return op;
}
@ -346,5 +326,26 @@ namespace mongo {
}
return ops[ 0 ];
}
void QueryPlanSet::Runner::initOp( QueryOp &op ) {
try {
op.init();
} catch ( const std::exception &e ) {
op.setExceptionMessage( e.what() );
} catch ( ... ) {
op.setExceptionMessage( "Caught unknown exception" );
}
}
void QueryPlanSet::Runner::nextOp( QueryOp &op ) {
try {
if ( !op.error() )
op.next();
} catch ( const std::exception &e ) {
op.setExceptionMessage( e.what() );
} catch ( ... ) {
op.setExceptionMessage( "Caught unknown exception" );
}
}
} // namespace mongo

View File

@ -122,6 +122,8 @@ namespace mongo {
shared_ptr< QueryOp > run();
QueryOp &op_;
QueryPlanSet &plans_;
static void initOp( QueryOp &op );
static void nextOp( QueryOp &op );
};
FieldBoundSet fbs_;
PlanSet plans_;

View File

@ -518,7 +518,7 @@ namespace QueryOptimizerTests {
Helpers::ensureIndex( ns(), BSON( "a" << 1 ), "a_1" );
Helpers::ensureIndex( ns(), BSON( "a" << 1 ), "b_2" );
QueryPlanSet s( ns(), BSON( "a" << 4 ), emptyObj );
ASSERT_EQUALS( 2, s.nPlans() );
ASSERT_EQUALS( 1, s.nPlans() );
}
};
@ -782,10 +782,10 @@ namespace QueryOptimizerTests {
void run() {
Helpers::ensureIndex( ns(), BSON( "a" << 1 ), "a_1" );
QueryPlanSet s( ns(), BSON( "a" << 4 ), emptyObj );
QueryPlanSet s( ns(), BSON( "a" << 4 ), BSON( "b" << 1 ) );
ScanOnlyTestOp op;
s.runOp( op );
ASSERT( !fromjson( "{$natural:1}" ).woCompare( indexForPattern( ns(), s.fbs().pattern() ) ) );
ASSERT( fromjson( "{$natural:1}" ).woCompare( indexForPattern( ns(), s.fbs().pattern() ) ) == 0 );
QueryPlanSet s2( ns(), BSON( "a" << 4 ), emptyObj );
TestOp op2;
@ -849,13 +849,15 @@ namespace QueryOptimizerTests {
public:
void run() {
Helpers::ensureIndex( ns(), BSON( "_id" << 1 ), "_id_1" );
BSONObj one = BSON( "_id" << 2 );
BSONObj two = BSON( "_id" << 1 );
BSONObj one = BSON( "_id" << 3 << "a" << 1 );
BSONObj two = BSON( "_id" << 2 << "a" << 1 );
BSONObj three = BSON( "_id" << 1 << "a" << -1 );
theDataFileMgr.insert( ns(), one );
theDataFileMgr.insert( ns(), two );
theDataFileMgr.insert( ns(), three );
BSONObj id;
deleteObjects( ns(), BSON( "_id" << GT << 0 ), true, &id );
ASSERT_EQUALS( 2, id.getIntField( "_id" ) );
deleteObjects( ns(), BSON( "_id" << GT << 0 << "a" << GT << 0 ), true, &id );
ASSERT_EQUALS( 3, id.getIntField( "_id" ) );
}
};