summaryrefslogtreecommitdiff
path: root/jstests/explain4.js
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2012-02-14 09:30:08 -0800
committerAaron <aaron@10gen.com>2012-02-24 22:49:08 -0800
commitafc4e7fe813a753bf24414ff1385226d8ebbbd86 (patch)
tree8f9e15194fb18651a9c7e73635fe7a5c6176758b /jstests/explain4.js
parentcb40560b1a085f9cd0e632b3e6879d6611df10dc (diff)
downloadmongo-afc4e7fe813a753bf24414ff1385226d8ebbbd86.tar.gz
4150 explain implementation checkpoint
Diffstat (limited to 'jstests/explain4.js')
-rw-r--r--jstests/explain4.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/jstests/explain4.js b/jstests/explain4.js
new file mode 100644
index 00000000000..bc997639ee8
--- /dev/null
+++ b/jstests/explain4.js
@@ -0,0 +1,54 @@
+// Basic validation of explain output fields
+
+t = db.jstests_explain4;
+t.drop();
+
+function checkField( name, value ) {
+ assert( explain.hasOwnProperty( name ) );
+ if ( value != null ) {
+ assert.eq( value, explain[ name ], name );
+ }
+}
+
+function checkPlanFields( explain, matches, n ) {
+ checkField( "cursor", "BasicCursor" );
+ checkField( "n", n );
+ checkField( "nscannedObjects", matches );
+ checkField( "nscanned", matches );
+ checkField( "indexBounds", {} );
+}
+
+function checkFields( matches, sort, limit ) {
+ it = t.find();
+ if ( sort ) {
+ it.sort({a:1});
+ }
+ if ( limit ) {
+ it.limit( limit );
+ }
+ explain = it.explain( true );
+ printjson( explain );
+ checkPlanFields( explain, matches, matches > 0 ? 1 : 0 );
+ checkField( "scanAndOrder", sort );
+ checkField( "millis" );
+ checkField( "nYields" );
+ checkField( "nChunkSkips", 0 );
+ checkField( "isMultiKey", false );
+// checkField( "indexOnly", false );
+ checkField( "server" );
+ checkField( "allPlans" );
+ explain.allPlans.forEach( function( x ) { checkPlanFields( x, matches ); } );
+}
+
+checkFields( 0, false );
+checkFields( 0, true );
+
+t.save( {} );
+checkFields( 1, false );
+checkFields( 1, true );
+
+t.save( {} );
+checkFields( 1, false, 1 );
+//checkFields( 2, true, 1 );
+//
+//// check all other fields, eg oldPlan