summaryrefslogtreecommitdiff
path: root/jstests/cqf/nonselective_index.js
blob: f951ae7dc40371660e6daa9b4dd7a169481c8b0b (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
/**
 * Tests scenario related to SERVER-13065.
 */
(function() {
"use strict";

load("jstests/libs/optimizer_utils.js");  // For checkCascadesOptimizerEnabled.
if (!checkCascadesOptimizerEnabled(db)) {
    jsTestLog("Skipping test because the optimizer is not enabled");
    return;
}

const t = db.cqf_nonselective_index;
t.drop();

const bulk = t.initializeUnorderedBulkOp();
const nDocs = 1000;
for (let i = 0; i < nDocs; i++) {
    bulk.insert({a: i});
}
assert.commandWorked(bulk.execute());

assert.commandWorked(t.createIndex({a: 1}));

// We pick collection scan since the query is not selective.
const res = t.explain("executionStats").aggregate([{$match: {a: {$gte: 0}}}]);
assert.eq(nDocs, res.executionStats.nReturned);

assert.eq("PhysicalScan", res.queryPlanner.winningPlan.optimizerPlan.child.child.nodeType);
}());