summaryrefslogtreecommitdiff
path: root/jstests/queryoptimizer6.js
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-03-01 13:43:25 +0100
committerAntonin Kral <a.kral@bobek.cz>2012-03-01 13:43:25 +0100
commitba59b00736b5b8dc0f0bd46397575aaf0cd4d44f (patch)
tree6364cf3f69677758a13f7aa5f6f06a8ebb652d98 /jstests/queryoptimizer6.js
parentf0d9a01bccdaeb466c12c92057914bbfef59526c (diff)
downloadmongodb-ba59b00736b5b8dc0f0bd46397575aaf0cd4d44f.tar.gz
Imported Upstream version 2.0.3
Diffstat (limited to 'jstests/queryoptimizer6.js')
-rw-r--r--jstests/queryoptimizer6.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/queryoptimizer6.js b/jstests/queryoptimizer6.js
new file mode 100644
index 0000000..fce92d7
--- /dev/null
+++ b/jstests/queryoptimizer6.js
@@ -0,0 +1,28 @@
+// Test that $ne constraints are accounted for in QueryPattern. SERVER-4665
+
+t = db.jstests_queryoptimizer6;
+
+function reset() {
+ t.drop();
+ t.save( {a:1} );
+ t.ensureIndex( {b:1}, {sparse:true} );
+}
+
+reset();
+// The sparse index will be used, and recorded for this query pattern.
+assert.eq( 0, t.find( {a:1,b:{$ne:1}} ).itcount() );
+// The query pattern should be different, and the sparse index should not be used.
+assert.eq( 1, t.find( {a:1} ).itcount() );
+
+reset();
+// The sparse index will be used, and (for better or worse) recorded for this query pattern.
+assert.eq( 0, t.find( {a:1} ).min({b:1}).itcount() );
+// The sparse index should not be used, even though the query patterns match.
+assert.eq( 1, t.find( {a:1} ).itcount() );
+
+reset();
+t.ensureIndex( {a:1,b:1} );
+// The sparse index will be used, and (for better or worse) recorded for this query pattern.
+assert.eq( 0, t.find( {a:1,b:null} ).min({b:1}).itcount() );
+// Descriptive test - the recorded {b:1} index is used, because it is not useless.
+assert.eq( 0, t.find( {a:1,b:null} ).itcount() );