summaryrefslogtreecommitdiff
path: root/jstests/explain1.js
blob: 4c92b102e38199f44bf09c46bdf20241be56e88e (plain)
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

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

for ( var i=0; i<100; i++ ){
    t.save( { x : i } );
}

q = { x : { $gt : 50 } };

assert.eq( 49 , t.find( q ).count() , "A" );
assert.eq( 49 , t.find( q ).itcount() , "B" );
assert.eq( 20 , t.find( q ).limit(20).itcount() , "C" );

t.ensureIndex( { x : 1 } );

assert.eq( 49 , t.find( q ).count() , "D" );
assert.eq( 49 , t.find( q ).itcount() , "E" );
assert.eq( 20 , t.find( q ).limit(20).itcount() , "F" );

assert.eq( 49 , t.find(q).explain().n , "G" );
assert.eq( 20 , t.find(q).limit(20).explain().n , "H" );
assert.eq( 20 , t.find(q).limit(-20).explain().n , "I" );
assert.eq( 49 , t.find(q).batchSize(20).explain().n , "J" );

// verbose explain output with stats
// display index bounds

var explainGt = t.find({x: {$gt: 5}}).explain(true);
var boundsVerboseGt = explainGt.stats.children[0].boundsVerbose;

print('explain stats for $gt = ' + tojson(explainGt.stats));

var explainGte = t.find({x: {$gte: 5}}).explain(true);
var boundsVerboseGte = explainGte.stats.children[0].boundsVerbose;

print('explain stats for $gte = ' + tojson(explainGte.stats));

print('index bounds for $gt  = ' + tojson(explainGt.indexBounds));
print('index bounds for $gte = ' + tojson(explainGte.indexBounds));

print('verbose bounds for $gt  = ' + tojson(boundsVerboseGt));
print('verbose bounds for $gte = ' + tojson(boundsVerboseGte));

// Since the verbose bounds are opaque, all we try to confirm is that the
// verbose bounds for $gt is different from those generated for $gte.
assert.neq(boundsVerboseGt, boundsVerboseGte,
           'verbose bounds for $gt and $gte should not be the same');