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
|
/**
* Tests that an index properly reports multikeyness and multikey paths metadata in the presence of
* successful and unsuccessful inserts.
* @tags: [
* assumes_read_concern_local,
* ]
*/
(function() {
"use strict";
// For making assertions about explain output.
load("jstests/libs/analyze_plan.js");
const coll = db.getCollection("index_multikey");
coll.drop();
function getIndexScanExplainOutput() {
const explain = coll.find().hint({a: 1, b: 1}).explain();
assert.commandWorked(explain);
return getPlanStage(getWinningPlan(explain.queryPlanner), "IXSCAN");
}
assert.commandWorked(coll.createIndex({a: 1, b: 1}));
assert.commandWorked(coll.createIndex({"a.0.0": 1}));
let ixscan = getIndexScanExplainOutput();
assert.eq(
ixscan.isMultiKey, false, "empty index should not be marked multikey; plan: " + tojson(ixscan));
assert.eq(ixscan.multiKeyPaths,
{a: [], b: []},
"empty index should have no multiKeyPaths; plan: " + tojson(ixscan));
assert.commandWorked(coll.insert({a: [1, 2, 3]}));
ixscan = getIndexScanExplainOutput();
assert.eq(ixscan.isMultiKey,
true,
"index should have been marked as multikey after insert; plan: " + tojson(ixscan));
assert.eq(ixscan.multiKeyPaths,
{a: ["a"], b: []},
"index has wrong multikey paths after insert; plan: " + ixscan);
})();
|