summaryrefslogtreecommitdiff
path: root/jstests/core/stages_and_hash.js
blob: aa91f27e542af14c164ac07a66894efdafe2cf56 (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
62
63
64
65
66
67
68
// @tags: [
//   does_not_support_stepdowns,
//   uses_testing_only_commands,
// ]

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

var collname = "stages_and_hashed";

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});

// Scan foo <= 20
ixscan1 = {
    ixscan: {
        args: {
            name: "stages_and_hashed",
            keyPattern: {foo: 1},
            startKey: {"": 20},
            endKey: {},
            startKeyInclusive: true,
            endKeyInclusive: true,
            direction: -1
        }
    }
};

// Scan bar >= 40
ixscan2 = {
    ixscan: {
        args: {
            name: "stages_and_hashed",
            keyPattern: {bar: 1},
            startKey: {"": 40},
            endKey: {},
            startKeyInclusive: true,
            endKeyInclusive: true,
            direction: 1
        }
    }
};

// bar = 50 - foo
// Intersection is (foo=0 bar=50, foo=1 bar=49, ..., foo=10 bar=40)
andix1ix2 = {
    andHash: {args: {nodes: [ixscan1, ixscan2]}}
};
res = db.runCommand({stageDebug: {plan: andix1ix2, collection: collname}});
assert.eq(res.ok, 1);
assert.eq(res.results.length, 11);

// Filter predicates from 2 indices.  Tests that we union the idx info.
andix1ix2filter = {
    fetch: {
        filter: {bar: {$in: [45, 46, 48]}, foo: {$in: [4, 5, 6]}},
        args: {node: {andHash: {args: {nodes: [ixscan1, ixscan2]}}}}
    }
};
res = db.runCommand({stageDebug: {collection: collname, plan: andix1ix2filter}});
assert.eq(res.ok, 1);
assert.eq(res.results.length, 2);