Skip to content

Commit

Permalink
SERVER-5288 Use appendNumber when writing long longs to explain output.
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Mar 22, 2012
1 parent a615a34 commit 44c4a5d
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 112 deletions.
17 changes: 14 additions & 3 deletions jstests/explain4.js
Expand Up @@ -7,15 +7,21 @@ function checkField( explain, name, value ) {
assert( explain.hasOwnProperty( name ) );
if ( value != null ) {
assert.eq( value, explain[ name ], name );
// Check that the value is of the expected type. SERVER-5288
assert.eq( typeof( value ), typeof( explain[ name ] ), 'type ' + name );
}
}

function checkPlanFields( explain, matches, n ) {
checkField( explain, "cursor", "BasicCursor" );
function checkNonCursorPlanFields( explain, matches, n ) {
checkField( explain, "n", n );
checkField( explain, "nscannedObjects", matches );
checkField( explain, "nscanned", matches );
checkField( explain, "indexBounds", {} );
}

function checkPlanFields( explain, matches, n ) {
checkField( explain, "cursor", "BasicCursor" );
checkField( explain, "indexBounds", {} );
checkNonCursorPlanFields( explain, matches, n );
}

function checkFields( matches, sort, limit ) {
Expand Down Expand Up @@ -50,3 +56,8 @@ checkFields( 1, true );
t.save( {} );
checkFields( 1, false, 1 );
checkFields( 2, true, 1 );

// Check basic fields with multiple clauses.
t.save( { _id:0 } );
explain = t.find( { $or:[ { _id:0 }, { _id:1 } ] } ).explain( true );
checkNonCursorPlanFields( explain, 1, 1 );
20 changes: 10 additions & 10 deletions src/mongo/db/explain.cpp
Expand Up @@ -72,9 +72,9 @@ namespace mongo {
BSONObj ExplainPlanInfo::bson() const {
BSONObjBuilder bob;
bob << "cursor" << _cursorName;
bob << "n" << _n;
bob << "nscannedObjects" << _nscannedObjects;
bob << "nscanned" << _nscanned;
bob.appendNumber( "n", _n );
bob.appendNumber( "nscannedObjects", _nscannedObjects );
bob.appendNumber( "nscanned", _nscanned );
bob << "indexBounds" << _indexBounds;
return bob.obj();
}
Expand All @@ -83,13 +83,13 @@ namespace mongo {
BSONObjBuilder bob;
bob << "cursor" << _cursorName;
bob << "isMultiKey" << _isMultiKey;
bob << "n" << clauseInfo.n();
bob << "nscannedObjects" << clauseInfo.nscannedObjects();
bob << "nscanned" << clauseInfo.nscanned();
bob.appendNumber( "n", clauseInfo.n() );
bob.appendNumber( "nscannedObjects", clauseInfo.nscannedObjects() );
bob.appendNumber( "nscanned", clauseInfo.nscanned() );
bob << "scanAndOrder" << _scanAndOrder;
bob << "indexOnly" << _indexOnly;
bob << "nYields" << _nYields;
bob << "nChunkSkips" << clauseInfo.nChunkSkips();
bob.appendNumber( "nChunkSkips", clauseInfo.nChunkSkips() );
bob << "millis" << clauseInfo.millis();
bob << "indexBounds" << _indexBounds;
bob.appendElements( _details );
Expand Down Expand Up @@ -214,9 +214,9 @@ namespace mongo {
nscanned += (*i)->nscanned();
}
clauseArray.done();
bob << "n" << n;
bob << "nscannedObjects" << nscannedObjects;
bob << "nscanned" << nscanned;
bob.appendNumber( "n", n );
bob.appendNumber( "nscannedObjects", nscannedObjects );
bob.appendNumber( "nscanned", nscanned );
bob << "millis" << _timer.duration();
}

Expand Down

0 comments on commit 44c4a5d

Please sign in to comment.