summaryrefslogtreecommitdiff
path: root/jstests/explain5.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/explain5.js')
-rw-r--r--jstests/explain5.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/jstests/explain5.js b/jstests/explain5.js
new file mode 100644
index 00000000000..a90f0726317
--- /dev/null
+++ b/jstests/explain5.js
@@ -0,0 +1,38 @@
+// Check that the explain result count does proper deduping.
+
+t = db.jstests_explain5;
+t.drop();
+
+t.ensureIndex( {a:1} );
+t.ensureIndex( {b:1} );
+
+t.save( {a:[1,2,3],b:[4,5,6]} );
+for( i = 0; i < 10; ++i ) {
+ t.save( {} );
+}
+
+// Check with a single in order plan.
+
+explain = t.find( {a:{$gt:0}} ).explain( true );
+assert.eq( 1, explain.n );
+assert.eq( 1, explain.allPlans[ 0 ].n );
+
+// Check with a single out of order plan.
+
+explain = t.find( {a:{$gt:0}} ).sort( {z:1} ).hint( {a:1} ).explain( true );
+assert.eq( 1, explain.n );
+assert.eq( 1, explain.allPlans[ 0 ].n );
+
+// Check with multiple plans.
+
+explain = t.find( {a:{$gt:0},b:{$gt:0}} ).explain( true );
+assert.eq( 1, explain.n );
+assert.eq( 1, explain.allPlans[ 0 ].n );
+assert.eq( 1, explain.allPlans[ 1 ].n );
+
+explain = t.find( {$or:[{a:{$gt:0},b:{$gt:0}},{a:{$gt:-1},b:{$gt:-1}}]} ).explain( true );
+assert.eq( 1, explain.n );
+// Check 'n' for every alternative query plan.
+for (var i = 0; i < explain.allPlans.length; ++i) {
+ assert.eq( 1, explain.allPlans[i].n );
+}