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

More accurate nScanned recording with plan

This commit is contained in:
Aaron 2009-02-26 15:09:44 -05:00
parent 09bfd068ba
commit 4d3100a66d
2 changed files with 10 additions and 1 deletions

View File

@ -302,19 +302,24 @@ namespace mongo {
}
int nScanned = 0;
int nScannedBackup = 0;
while( 1 ) {
++nScanned;
unsigned errCount = 0;
bool first = true;
for( vector< shared_ptr< QueryOp > >::iterator i = ops.begin(); i != ops.end(); ++i ) {
QueryOp &op = **i;
nextOp( op );
if ( op.complete() ) {
if ( first )
nScanned += nScannedBackup;
if ( plans_.mayRecordPlan_ && op.mayRecordPlan() )
op.qp().registerSelf( nScanned );
return *i;
}
if ( op.error() )
++errCount;
first = false;
}
if ( errCount == ops.size() )
break;
@ -332,7 +337,8 @@ namespace mongo {
}
plans_.mayRecordPlan_ = true;
plans_.usingPrerecordedPlan_ = false;
// TODO Don't write wrong nScanned if we complete on another plan.
nScannedBackup = nScanned;
nScanned = 0;
}
}
return ops[ 0 ];

View File

@ -796,6 +796,7 @@ namespace QueryOptimizerTests {
ScanOnlyTestOp op;
s.runOp( op );
ASSERT( fromjson( "{$natural:1}" ).woCompare( indexForPattern( ns(), s.fbs().pattern( BSON( "b" << 1 ) ) ) ) == 0 );
ASSERT_EQUALS( 1, nScannedForPattern( ns(), s.fbs().pattern( BSON( "b" << 1 ) ) ) );
QueryPlanSet s2( ns(), BSON( "a" << 4 ), BSON( "b" << 1 ) );
TestOp op2;
@ -852,6 +853,7 @@ namespace QueryOptimizerTests {
theDataFileMgr.insert( ns(), one );
deleteObjects( ns(), BSON( "a" << 1 ), false );
ASSERT( BSON( "a" << 1 ).woCompare( indexForPattern( ns(), FieldBoundSet( ns(), BSON( "a" << 1 ) ).pattern() ) ) == 0 );
ASSERT_EQUALS( 2, nScannedForPattern( ns(), FieldBoundSet( ns(), BSON( "a" << 1 ) ).pattern() ) );
}
};
@ -908,6 +910,7 @@ namespace QueryOptimizerTests {
assembleRequest( ns(), QUERY( "b" << 99 << "a" << GTE << 0 ).obj, 2, 0, 0, 0, m2 );
runQuery( m2, ss );
ASSERT( BSON( "a" << 1 ).woCompare( indexForPattern( ns(), FieldBoundSet( ns(), BSON( "b" << 0 << "a" << GTE << 0 ) ).pattern() ) ) == 0 );
ASSERT_EQUALS( 2, nScannedForPattern( ns(), FieldBoundSet( ns(), BSON( "b" << 0 << "a" << GTE << 0 ) ).pattern() ) );
}
};