summaryrefslogtreecommitdiff
path: root/jstests/core/explain6.js
blob: 11fa61d79e63b4c40d9857a60495e4ae21d661c1 (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
// @tags: [requires_non_retryable_writes, assumes_balancer_off]

// Basic test which checks the number of documents returned, keys examined, and documents
// examined as reported by explain.

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

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

t.save({a: 0, b: 1});
t.save({a: 1, b: 0});

explain = t.find({a: {$gte: 0}, b: {$gte: 0}}).explain(true);

assert.eq(2, explain.executionStats.nReturned);
assert.eq(2, explain.executionStats.totalKeysExamined);
assert.eq(2, explain.executionStats.totalDocsExamined);

// A limit of 2.
explain = t.find({a: {$gte: 0}, b: {$gte: 0}}).limit(-2).explain(true);
assert.eq(2, explain.executionStats.nReturned);

// A $or query.
explain = t.find({$or: [{a: {$gte: 0}, b: {$gte: 1}}, {a: {$gte: 1}, b: {$gte: 0}}]}).explain(true);
assert.eq(2, explain.executionStats.nReturned);

// A non $or case where totalKeysExamined != number of results
t.remove({});

t.save({a: '0', b: '1'});
t.save({a: '1', b: '0'});
explain = t.find({a: /0/, b: /1/}).explain(true);
assert.eq(1, explain.executionStats.nReturned);
assert.eq(2, explain.executionStats.totalKeysExamined);