summaryrefslogtreecommitdiff
path: root/jstests/core/explain4.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/explain4.js')
-rw-r--r--jstests/core/explain4.js70
1 files changed, 10 insertions, 60 deletions
diff --git a/jstests/core/explain4.js b/jstests/core/explain4.js
index d6d3d818a72..effd080d8fd 100644
--- a/jstests/core/explain4.js
+++ b/jstests/core/explain4.js
@@ -1,68 +1,18 @@
-// Basic validation of explain output fields.
+// Test that limit is applied by explain.
t = db.jstests_explain4;
t.drop();
-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 checkNonCursorPlanFields( explain, matches, n ) {
- checkField( explain, "n", n );
- checkField( explain, "nscannedObjects", matches );
- checkField( explain, "nscanned", matches );
-}
-
-function checkPlanFields( explain, matches, n ) {
- checkField( explain, "cursor", "BasicCursor" );
- // index related fields do not appear in non-indexed plan
- assert(!("indexBounds" in explain));
- checkNonCursorPlanFields( explain, matches, n );
-}
+t.ensureIndex( { a:1 } );
-function checkFields( matches, sort, limit ) {
- cursor = t.find();
- if ( sort ) {
- print("sort is {a:1}");
- cursor.sort({a:1});
- }
- if ( limit ) {
- print("limit = " + limit);
- cursor.limit( limit );
- }
- explain = cursor.explain( true );
- printjson( explain );
- checkPlanFields( explain, matches, matches > 0 ? 1 : 0 );
- checkField( explain, "scanAndOrder", sort );
- checkField( explain, "millis" );
- checkField( explain, "nYields" );
- checkField( explain, "nChunkSkips", 0 );
- checkField( explain, "isMultiKey", false );
- checkField( explain, "indexOnly", false );
- checkField( explain, "server" );
- checkField( explain, "allPlans" );
- explain.allPlans.forEach( function( x ) { checkPlanFields( x, matches, matches ); } );
+for( i = 0; i < 10; ++i ) {
+ t.save( { a:i, b:0 } );
}
-checkFields( 0, false );
-
-// If there's nothing in the collection, there's no point in verifying that a sort
-// is done.
-// checkFields( 0, true );
-
-t.save( {} );
-checkFields( 1, false );
-checkFields( 1, true );
-
-t.save( {} );
-checkFields( 1, false, 1 );
+explain = t.find( { a:{ $gte:0 }, b:0 } ).sort( { a:1 } )
+ .hint( { a:1 } )
+ .limit( 5 )
+ .explain( true );
-// Check basic fields with multiple clauses.
-t.save( { _id:0 } );
-explain = t.find( { $or:[ { _id:0 }, { _id:1 } ] } ).explain( true );
-checkNonCursorPlanFields( explain, 1, 1 );
+// Five results are expected, matching the limit spec.
+assert.eq( 5, explain.executionStats.nReturned );