summaryrefslogtreecommitdiff
path: root/jstests/explain4.js
blob: fe5cf73d7b71c9a8ba0b82eb0db534e3efd5eff1 (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
49
50
51
52
// Basic validation of explain output fields

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

function checkField( name, value ) {
    assert( explain.hasOwnProperty( name ) );
    if ( value != null ) {
        assert.eq( value, explain[ name ], name );
    }
}

function checkPlanFields( explain, matches, n ) {
    checkField( "cursor", "BasicCursor" );
    checkField( "n", n );
    checkField( "nscannedObjects", matches );
    checkField( "nscanned", matches );    
    checkField( "indexBounds", {} );
}

function checkFields( matches, sort, limit ) {
    it = t.find();
    if ( sort ) {
        it.sort({a:1});
    }
    if ( limit ) {
        it.limit( limit );
    }
    explain = it.explain( true );
//    printjson( explain );
    checkPlanFields( explain, matches, matches > 0 ? 1 : 0 );
    checkField( "scanAndOrder", sort );
    checkField( "millis" );
    checkField( "nYields" );
    checkField( "nChunkSkips", 0 );
    checkField( "isMultiKey", false );
    checkField( "indexOnly", false );
    checkField( "server" );
    checkField( "allPlans" );
    explain.allPlans.forEach( function( x ) { checkPlanFields( x, matches ); } );
}

checkFields( 0, false );
checkFields( 0, true );

t.save( {} );
checkFields( 1, false );
checkFields( 1, true );

t.save( {} );
checkFields( 1, false, 1 );
checkFields( 2, true, 1 );