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
|
/**
* Test that indexes on arrays can satisfy an $eq/$lt predicate, which matches if any
* array element matches.
*
* @tags: [
* # Checks for 'IndexScan' node in explain.
* requires_cqf,
* ]
*/
(function() {
"use strict";
load("jstests/libs/optimizer_utils.js"); // For getPlanSkeleton.
db.setLogLevel(4, "query");
const coll = db.cqf_array_index;
coll.drop();
assert.commandWorked(coll.insert([
{a: [1, 2, 3, 4]},
{a: [2, 3, 4]},
{a: [2]},
{a: 2},
{a: [1, 3]},
]));
// Generate enough documents for index to be preferable.
assert.commandWorked(coll.insert(Array.from({length: 100}, (_, i) => ({a: i + 10}))));
assert.commandWorked(coll.createIndex({a: 1}));
function run(pipeline) {
jsTestLog(`Query: ${tojsononeline(pipeline)}`);
show(coll.aggregate(pipeline));
const explain = coll.explain("executionStats").aggregate(pipeline);
print(`nReturned: ${explain.executionStats.nReturned}\n`);
print(`Plan skeleton: `);
printjson(getPlanSkeleton(explain));
}
run([{$match: {a: 2}}, {$unset: '_id'}]);
run([{$match: {a: {$lt: 2}}}, {$unset: '_id'}]);
})();
|