File: queryoptimizer6.js

package info (click to toggle)
mongodb 1%3A2.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,204 kB
  • sloc: cpp: 109,783; ansic: 101,073; python: 2,287; perl: 395; makefile: 370; sh: 242; asm: 46
file content (28 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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() );