mongodb-explain-compat 3.0.4 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +41 -17
- package/package.json +6 -9
package/lib/index.js
CHANGED
|
@@ -5,19 +5,41 @@ const kSBENodes = Symbol('kSBENodes');
|
|
|
5
5
|
function mapPlanTree(stage, mapper, currentParent = null) {
|
|
6
6
|
const result = mapper(stage, currentParent);
|
|
7
7
|
const target = result || {};
|
|
8
|
-
if (stage.inputStage)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (stage.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (stage.
|
|
15
|
-
|
|
8
|
+
if (stage.inputStage) {
|
|
9
|
+
target.inputStage = mapPlanTree(stage.inputStage, mapper, stage);
|
|
10
|
+
}
|
|
11
|
+
if (stage.innerStage) {
|
|
12
|
+
target.innerStage = mapPlanTree(stage.innerStage, mapper, stage);
|
|
13
|
+
}
|
|
14
|
+
if (stage.outerStage) {
|
|
15
|
+
target.outerStage = mapPlanTree(stage.outerStage, mapper, stage);
|
|
16
|
+
}
|
|
17
|
+
if (stage.thenStage) {
|
|
18
|
+
target.thenStage = mapPlanTree(stage.thenStage, mapper, stage);
|
|
19
|
+
}
|
|
20
|
+
if (stage.elseStage) {
|
|
21
|
+
target.elseStage = mapPlanTree(stage.elseStage, mapper, stage);
|
|
22
|
+
}
|
|
23
|
+
if (stage.inputStages) {
|
|
24
|
+
target.inputStages = stage.inputStages.map((s) =>
|
|
25
|
+
mapPlanTree(s, mapper, stage)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (stage.shards) {
|
|
29
|
+
target.shards = stage.shards.map((s) => mapPlanTree(s, stage));
|
|
30
|
+
}
|
|
31
|
+
if (stage.executionStages) {
|
|
32
|
+
target.executionStages = stage.executionStages.map((s) =>
|
|
33
|
+
mapPlanTree(s, mapper, stage)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
16
36
|
return result;
|
|
17
37
|
}
|
|
18
38
|
|
|
19
39
|
function omitChildStages(stage) {
|
|
20
|
-
return mapPlanTree(stage, child =>
|
|
40
|
+
return mapPlanTree(stage, (child) =>
|
|
41
|
+
stage === child ? { ...stage } : undefined
|
|
42
|
+
);
|
|
21
43
|
}
|
|
22
44
|
|
|
23
45
|
function mapStages(queryPlan, sbeExecutionStages) {
|
|
@@ -25,7 +47,7 @@ function mapStages(queryPlan, sbeExecutionStages) {
|
|
|
25
47
|
|
|
26
48
|
// First, look up all stages from the query plan, and store their IDs so
|
|
27
49
|
// that we know which SBE nodes we should assign to which query plan node.
|
|
28
|
-
mapPlanTree(queryPlan, stage => {
|
|
50
|
+
mapPlanTree(queryPlan, (stage) => {
|
|
29
51
|
if (stage.planNodeId) {
|
|
30
52
|
nodeIdToQueryPlan.set(stage.planNodeId, stage);
|
|
31
53
|
stage[kSBENodes] = [];
|
|
@@ -53,21 +75,23 @@ function mapStages(queryPlan, sbeExecutionStages) {
|
|
|
53
75
|
// Do the actual mapping here. Use the head SBE node, and only aggregate
|
|
54
76
|
// 'docsExamined' based on all child nodes and 'executionTimeMillisEstimate'
|
|
55
77
|
// based on all top-level child nodes here.
|
|
56
|
-
return mapPlanTree(queryPlan, stage => {
|
|
78
|
+
return mapPlanTree(queryPlan, (stage) => {
|
|
57
79
|
const sbeNodes = stage[kSBENodes];
|
|
58
80
|
const headSBENode = sbeNodes[0] || {};
|
|
59
81
|
return {
|
|
60
82
|
...omitChildStages(headSBENode),
|
|
61
83
|
...omitChildStages(stage),
|
|
62
|
-
executionTimeMillisEstimate:
|
|
84
|
+
executionTimeMillisEstimate:
|
|
85
|
+
headSBENode.executionTimeMillis ||
|
|
86
|
+
headSBENode.executionTimeMillisEstimate,
|
|
63
87
|
docsExamined: sbeNodes
|
|
64
|
-
.filter(sbe => sbe.stage === 'seek' || sbe.stage === 'scan')
|
|
65
|
-
.map(sbe => sbe.numReads || 0)
|
|
88
|
+
.filter((sbe) => sbe.stage === 'seek' || sbe.stage === 'scan')
|
|
89
|
+
.map((sbe) => sbe.numReads || 0)
|
|
66
90
|
.reduce((a, b) => a + b, 0),
|
|
67
91
|
keysExamined: sbeNodes
|
|
68
|
-
.filter(sbe => sbe.stage === 'ixseek' || sbe.stage === 'ixscan')
|
|
69
|
-
.map(sbe => sbe.numReads || 0)
|
|
70
|
-
.reduce((a, b) => a + b, 0)
|
|
92
|
+
.filter((sbe) => sbe.stage === 'ixseek' || sbe.stage === 'ixscan')
|
|
93
|
+
.map((sbe) => sbe.numReads || 0)
|
|
94
|
+
.reduce((a, b) => a + b, 0),
|
|
71
95
|
};
|
|
72
96
|
});
|
|
73
97
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb-explain-compat",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Convert mongodb SBE explain output to 4.4 explain output",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mongodb",
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
"compass:main": "lib/index.js",
|
|
12
12
|
"exports": {
|
|
13
13
|
"import": "./.esm-wrapper.mjs",
|
|
14
|
-
"require": "./lib/index.js"
|
|
14
|
+
"require": "./lib/index.js",
|
|
15
|
+
"types": "./index.d.ts"
|
|
15
16
|
},
|
|
16
17
|
"compass:exports": {
|
|
17
18
|
".": "./lib/index.js"
|
|
18
19
|
},
|
|
20
|
+
"types": "./index.d.ts",
|
|
19
21
|
"files": [
|
|
20
22
|
"LICENSE",
|
|
21
23
|
"lib",
|
|
@@ -45,16 +47,11 @@
|
|
|
45
47
|
},
|
|
46
48
|
"license": "SSPL",
|
|
47
49
|
"devDependencies": {
|
|
50
|
+
"@mongodb-js/eslint-config-compass": "^1.1.7",
|
|
48
51
|
"eslint": "^7.25.0",
|
|
49
|
-
"eslint-config-semistandard": "^15.0.1",
|
|
50
|
-
"eslint-config-standard": "^14.1.1",
|
|
51
|
-
"eslint-plugin-import": "^2.22.0",
|
|
52
|
-
"eslint-plugin-node": "^11.1.0",
|
|
53
|
-
"eslint-plugin-promise": "^4.2.1",
|
|
54
|
-
"eslint-plugin-standard": "^4.0.1",
|
|
55
52
|
"gen-esm-wrapper": "^1.1.0",
|
|
56
53
|
"mocha": "^10.2.0",
|
|
57
54
|
"nyc": "^15.1.0"
|
|
58
55
|
},
|
|
59
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "b35fb1b3fc1c73d009c0d2601fe1c3a4f699de29"
|
|
60
57
|
}
|