summaryrefslogtreecommitdiff
path: root/jstests/core/orp.js
blob: 18abdfbc63a1853f1761b647fc66991d8bc5a836 (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
// $or clause deduping with result set sizes > 101 (smaller result sets are now also deduped by the
// query optimizer cursor).

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

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

for( i = 0; i < 200; ++i ) {
    t.save( { a:1, b:1 } );
}

// Deduping results from the previous clause.
assert.eq( 200, t.count( { $or:[ { a:1 }, { b:1 } ] } ) );

// Deduping results from a prior clause.
assert.eq( 200, t.count( { $or:[ { a:1 }, { c:1 }, { b:1 } ] } ) );
t.save( { c:1 } );
assert.eq( 201, t.count( { $or:[ { a:1 }, { c:1 }, { b:1 } ] } ) );

// Deduping results that would normally be index only matches on overlapping and double scanned $or
// field regions.
t.drop();
t.ensureIndex( { a:1, b:1 } );
for( i = 0; i < 16; ++i ) {
    for( j = 0; j < 16; ++j ) {
        t.save( { a:i, b:j } );
    }
}
assert.eq( 16 * 16,
          t.count( { $or:[ { a:{ $gte:0 }, b:{ $gte:0 } }, { a:{ $lte:16 }, b:{ $lte:16 } } ] } ) );

// Deduping results from a clause that completed before the multi cursor takeover.
t.drop();
t.ensureIndex( { a:1 } );
t.ensureIndex( { b:1 } );
t.save( { a:1,b:200 } );
for( i = 0; i < 200; ++i ) {
    t.save( { b:i } );
}
assert.eq( 201, t.count( { $or:[ { a:1 }, { b:{ $gte:0 } } ] } ) );