summaryrefslogtreecommitdiff
path: root/jstests/indexo.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/indexo.js')
-rw-r--r--jstests/indexo.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/indexo.js b/jstests/indexo.js
new file mode 100644
index 0000000..e50c099
--- /dev/null
+++ b/jstests/indexo.js
@@ -0,0 +1,32 @@
+// Check that dummy basic cursors work correctly SERVER-958.
+
+t = db.jstests_indexo;
+t.drop();
+
+function checkDummyCursor( explain ) {
+ assert.eq( "BasicCursor", explain.cursor );
+ assert.eq( 0, explain.nscanned );
+ assert.eq( 0, explain.n );
+}
+
+t.save( {a:1} );
+
+t.ensureIndex( {a:1} );
+
+// Match is impossible, so no documents should be scanned.
+checkDummyCursor( t.find( {a:{$gt:5,$lt:0}} ).explain() );
+
+t.drop();
+checkDummyCursor( t.find( {a:1} ).explain() );
+
+t.save( {a:1} );
+t.ensureIndex( {a:1} );
+checkDummyCursor( t.find( {$or:[{a:{$gt:5,$lt:0}},{a:1}]} ).explain().clauses[ 0 ] );
+
+t.drop();
+t.save( {a:5,b:[1,2]} );
+t.ensureIndex( {a:1,b:1} );
+t.ensureIndex( {a:1} );
+// The first clause will use index {a:1,b:1} with the current implementation.
+// The second clause has no valid values for index {a:1} so it will use a dummy cursor.
+checkDummyCursor( t.find( {$or:[{b:{$exists:true},a:{$gt:4}},{a:{$lt:6,$gt:4}}]} ).explain().clauses[ 1 ] );