summaryrefslogtreecommitdiff
path: root/jstests/core/stages_or.js
blob: 92f85b15694c7785a50075221a1b572810c5589f (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
// 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: {},
                          endKeyInclusive: true, direction: 1}}};
// foo >= 40
ixscan2 = {ixscan: {args:{keyPattern:{foo: 1},
                          startKey: {"": 40}, endKey: {},
                          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);