File: indexk.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (58 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (4)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Check correct result set when bounds each match different multikeys SERVER-958

t = db.jstests_indexk;
t.drop();

t.insert({a:[1,10]});

assert.eq( 1, t.count({a: {$gt:2, $lt:5}}) );
assert.eq( 1, t.count({a: {$gt:2}}) );
assert.eq( 1, t.count({a: {$lt:5}}) );

assert.eq( 1, t.count({a: {$gt:5, $lt:2}}) );
assert.eq( 1, t.count({a: {$gt:5}}) );
assert.eq( 1, t.count({a: {$lt:2}}) );

t.ensureIndex({a:1});

// Check that only one constraint limits the index range for a multikey index.
// The constraint used is arbitrary, but testing current behavior here.

assert.eq( 1, t.count({a: {$gt: 2, $lt:5}}) );
e = t.find({a: {$gt: 2, $lt:5}}).explain();
assert.eq( 1, e.nscanned );
assert.eq( 1, e.n );
assert.eq( 2, e.indexBounds.a[ 0 ][ 0 ] );
// Check that upper bound is large ( > 5 ).
assert.lt( 1000, e.indexBounds.a[ 0 ][ 1 ] );

assert.eq( 1, t.count({a: {$lt: 5, $gt:2}}) );
e = t.find({a: {$lt: 5, $gt:2}}).explain();
assert.eq( 1, e.nscanned );
assert.eq( 1, e.n );
// Check that upper bound is low ( < 2 ).
assert.gt( -1000, e.indexBounds.a[ 0 ][ 0 ] );
assert.eq( 5, e.indexBounds.a[ 0 ][ 1 ] );

// Now check cases where no match is possible with a single key index.

assert.eq( 1, t.count({a: {$gt: 5, $lt:2}}) );
e = t.find({a: {$gt: 5, $lt:2}}).explain();
assert.eq( 1, e.nscanned );
assert.eq( 1, e.n );
assert.eq( 5, e.indexBounds.a[ 0 ][ 0 ] );
// Check that upper bound is low ( < 2 ).
assert.lt( 1000, e.indexBounds.a[ 0 ][ 1 ] );

assert.eq( 1, t.count({a: {$lt: 2, $gt:5}}) );
e = t.find({a: {$lt: 2, $gt:5}}).explain();
assert.eq( 1, e.nscanned );
assert.eq( 1, e.n );
// Check that upper bound is large ( > 5 ).
assert.gt( -1000, e.indexBounds.a[ 0 ][ 0 ] );
assert.eq( 2, e.indexBounds.a[ 0 ][ 1 ] );

assert.eq( 1, t.count({a: {$gt: 2}}) );
assert.eq( 1, t.count({a: {$lt: 5}}) );

// Check good performance of single key index