File: queryoptimizer2.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 (67 lines) | stat: -rw-r--r-- 1,762 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
61
62
63
64
65
66
67

t = db.queryoptimizer2;

function debug( x ) {
//    printjson( x );
}

function doTest( f1, f2 ) {

    t.drop()
        
    for( i = 0; i < 30; ++i ) {
        t.save( { a:2, z:1 } );
    }

    for( i = 0; i < 30; ++i ) {
        t.save( { b:2, z:2 } );
    }

    for( i = 0; i < 60; ++i ) {
        t.save( { c:2, z:3 } );
    }

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

    e = t.find( { b:2, z:2 } ).batchSize( 100 ).explain( true );
    assert.eq( null, e.oldPlan );

    t.ensureIndex( { c:1 } ); // will clear query cache

    f1();

    assert( t.find( { a:2, z:1 } ).batchSize( 100 ).explain( true ).oldPlan );
    assert( t.find( { b:2, z:2 } ).batchSize( 100 ).explain( true ).oldPlan );

    e = t.find( { c:2, z:3 } ).batchSize( 100 ).explain( true );
    // no pattern should be recorded as a result of the $or query
    assert.eq( null, e.oldPlan );

    t.dropIndex( { b:1, z:2 } ); // clear query cache
    for( i = 0; i < 15; ++i ) {
        t.save( { a:2, z:1 } );
    }

    f2();
    // pattern should be recorded, since we transitioned to the takeover cursor and had over 50 matches
    assert( t.find( { c:2, z:3 } ).batchSize( 100 ).explain( true ).oldPlan );

}

doTest( function() {
       t.find( { $or: [ { a:2, z:1 }, { b:2, z:2 }, { c:2, z:3 } ] } ).batchSize( 100 ).toArray();
       },
       function() {
       t.find( { $or: [ { a:2, z:1 }, { c:2, z:3 } ] } ).batchSize( 100 ).toArray();       
       }
       );

doTest( function() {
       t.find( { $or: [ { a:2, z:1 }, { b:2, z:2 }, { c:2, z:3 } ] } ).limit(102).count( true );
       },
       function() {
       t.find( { $or: [ { a:2, z:1 }, { c:2, z:3 } ] } ).limit(102).count( true );       
       }
       );