summaryrefslogtreecommitdiff
path: root/jstests/core/stages_or.js
blob: 0fd78bdfc5cd030a48e9aa833594db7b35b54b23 (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
53
54
55
56
57
58
59
60
61
// @tags: [
//   does_not_support_stepdowns,
//   uses_testing_only_commands,
// ]

// Test basic OR functionality
t = db.stages_or;
t.drop();
var collname = "stages_or";

var N = 50;
for (var i = 0; i < N; ++i) {
    t.insert({foo: i, bar: N - i, baz: i});
}

t.ensureIndex({foo: 1});
t.ensureIndex({bar: 1});
t.ensureIndex({baz: 1});

// baz >= 40
ixscan1 = {
    ixscan: {
        args: {
            keyPattern: {baz: 1},
            startKey: {"": 40},
            endKey: {},
            startKeyInclusive: true,
            endKeyInclusive: true,
            direction: 1
        }
    }
};
// foo >= 40
ixscan2 = {
    ixscan: {
        args: {
            keyPattern: {foo: 1},
            startKey: {"": 40},
            endKey: {},
            startKeyInclusive: true,
            endKeyInclusive: true,
            direction: 1
        }
    }
};

// OR of baz and foo.  Baz == foo and we dedup.
orix1ix2 = {
    or: {args: {nodes: [ixscan1, ixscan2], dedup: true}}
};
res = db.runCommand({stageDebug: {collection: collname, plan: orix1ix2}});
assert.eq(res.ok, 1);
assert.eq(res.results.length, 10);

// No deduping, 2x the results.
orix1ix2nodd = {
    or: {args: {nodes: [ixscan1, ixscan2], dedup: false}}
};
res = db.runCommand({stageDebug: {collection: collname, plan: orix1ix2nodd}});
assert.eq(res.ok, 1);
assert.eq(res.results.length, 20);