blob: 7b35f71f99e630db34e0caa0e7eace9505c2cdd6 (
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
|
/**
* Tests the autoparameterization of the SBE cached plan that includes positional projection.
*/
(function() {
"use strict";
load("jstests/libs/collection_drop_recreate.js");
const coll = db.plan_cache_positional_projection;
coll.drop();
const nonMatchingDoc = {
"c": 3
};
const matchingDoc1 = {
"c": 2,
"a": {"b": 3}
};
const matchingDoc2 = {
"c": 2,
"a": {"b": 1}
};
const arr = {
"arr": [nonMatchingDoc, matchingDoc1, matchingDoc2]
};
assert.commandWorked(coll.insert(arr));
// Run a query which can populate the plan cache.
assert.eq(0,
coll.find({"arr": {"$elemMatch": {"c": 99, "a.b": {"$exists": true}}}}, {"arr.$": 1})
.itcount());
// Run the same query but with different constants. This query can use the plan cache entry created
// earlier.
const result =
coll.find({"arr": {"$elemMatch": {"c": 2, "a.b": {"$exists": true}}}}, {"arr.$": 1, "_id": 0})
.toArray();
assert.eq([{arr: [matchingDoc1]}], result, result);
}());
|