File: explaina.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 (47 lines) | stat: -rw-r--r-- 1,437 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
// Check explain results when an in order plan is selected among mixed in order and out of order
// plans.

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

t.ensureIndex( { a:1 } );
t.ensureIndex( { b:1 } );

for( i = 0; i < 1000; ++i ) {
    t.save( { a:i, b:i%3 } );
}

// Query with an initial set of documents.
explain1 = t.find( { a:{ $gte:0 }, b:2 } ).sort( { a:1 } ).explain( true );

for( i = 1000; i < 2000; ++i ) {
    t.save( { a:i, b:i%3 } );
}

// Query with some additional documents.
explain2 = t.find( { a:{ $gte:0 }, b:2 } ).sort( { a:1 } ).explain( true );

function plan( explain, cursor ) {
    for( i in explain.allPlans ) {
        e = explain.allPlans[ i ];
        if ( e.cursor == cursor ) {
            return e;
        }
    }
    assert( false );
}

// Check query totals.
assert.eq( 333, explain1.n );
assert.eq( 666, explain2.n );

// Check totals for the selected in order a:1 plan.
assert.eq( 333, plan( explain1, "BtreeCursor a_1" ).n );
assert.eq( 1000, plan( explain1, "BtreeCursor a_1" ).nscanned );
assert.eq( 666, plan( explain2, "BtreeCursor a_1" ).n );
assert.eq( 2000, plan( explain2, "BtreeCursor a_1" ).nscanned );

// Check that results only examined after the a:1 plan is selected will not affect plan explain
// output for other plans.
assert.eq( plan( explain1, "BtreeCursor b_1" ), plan( explain2, "BtreeCursor b_1" ) );
assert.eq( plan( explain1, "BasicCursor" ), plan( explain2, "BasicCursor" ) );