File: index_diag.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 (60 lines) | stat: -rw-r--r-- 1,948 bytes parent folder | download | duplicates (3)
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
59
60

t = db.index_diag
t.drop();

t.ensureIndex( { x : 1 } );

all = []
ids = []
xs = []

function r( a ){
    var n = []
    for ( var x=a.length-1; x>=0; x-- )
        n.push( a[x] );
    return n;
}

for ( i=1; i<4; i++ ){
    o = { _id : i , x : -i }
    t.insert( o );
    all.push( o );
    ids.push( { _id : i } );
    xs.push( { x : -i } );
}

assert.eq( all , t.find().sort( { _id : 1 } ).toArray() , "A1" );
assert.eq( r( all ) , t.find().sort( { _id : -1 } ).toArray() , "A2" );

assert.eq( all , t.find().sort( { x : -1 } ).toArray() , "A3" );
assert.eq( r( all ) , t.find().sort( { x : 1 } ).toArray() , "A4" );

assert.eq( ids , t.find().sort( { _id : 1 } )._addSpecial( "$returnKey" , true ).toArray() , "B1" )
assert.eq( r( ids ) , t.find().sort( { _id : -1 } )._addSpecial( "$returnKey" , true ).toArray() , "B2" )
assert.eq( xs , t.find().sort( { x : -1 } )._addSpecial( "$returnKey" , true ).toArray() , "B3" )
assert.eq( r( xs ) , t.find().sort( { x : 1 } )._addSpecial( "$returnKey" , true ).toArray() , "B4" )

assert.eq( r( xs ) , t.find().hint( { x : 1 } )._addSpecial( "$returnKey" , true ).toArray() , "B4" )

// SERVER-4981
t.ensureIndex( { _id : 1 , x : 1 } );
assert.eq( all ,
          t.find().hint( { _id : 1 , x : 1 } )._addSpecial( "$returnKey" , true ).toArray()
          )
assert.eq( r( all ) ,
          t.find().hint( { _id : 1 , x : 1 } ).sort( { x : 1 } )
          ._addSpecial( "$returnKey" , true ).toArray()
          )

// Descriptive test that a query involving multiple plans may return keys from multiple indexes.
t.dropIndex( { _id : 1 , x : 1 } );
ret =
t.find( { _id : { $gt : -10 }, x : { $gt : -10 } } )._addSpecial( "$returnKey" , true ).toArray()
keys = {};
for( i in ret ) {
    Object.extend( keys, ret[ i ] );
}
assert.eq( [ "_id" , "x" ], Object.keySet( keys ).sort() );

assert.eq( [ {} , {} , {} ],
          t.find().hint( { $natural : 1 } )._addSpecial( "$returnKey" , true ).toArray() )