Skip to content

Commit d31e550

Browse files
authored
fix AQL query profile output with older arangod versions (arangodb#20445)
1 parent da1b68b commit d31e550

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

js/common/modules/@arangodb/aql/explainer.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ function printStats(stats, isCoord) {
358358

359359
stringBuilder.appendLine(' ' + pad(1 + maxWELen - String(stats.writesExecuted).length) + value(stats.writesExecuted) + spc +
360360
pad(1 + maxWILen - String(stats.writesIgnored).length) + value(stats.writesIgnored) + spc +
361-
pad(1 + maxDLLen - String(stats.documentLookups).length) + value(stats.documentLookups) + spc +
361+
pad(1 + maxDLLen - String((stats.documentLookups || 0)).length) + value(stats.documentLookups || 0) + spc +
362362
pad(1 + maxSFLen - String(stats.scannedFull).length) + value(stats.scannedFull) + spc +
363363
pad(1 + maxSILen - String(stats.scannedIndex).length) + value(stats.scannedIndex) + spc +
364364
pad(1 + maxCHMLen - (String(stats.cacheHits || 0) + ' / ' + String(stats.cacheMisses || 0)).length) + value(stats.cacheHits || 0) + ' / ' + value(stats.cacheMisses || 0) + spc +
@@ -876,31 +876,41 @@ function processQuery(query, explain, planIndex) {
876876
};
877877
recursiveWalk(plan.nodes, 0, 'COOR');
878878

879-
if (profileMode) { // merge runtime info into plan
879+
if (profileMode) {
880+
// merge runtime info into plan.
881+
// note that this is only necessary for server versions <= 3.11.
882+
// the code can be removed when only supporting server versions
883+
// >= 3.12.
884+
stats.nodes.forEach(n => {
885+
nodes[n.id].runtime = n.runtime;
886+
});
880887
stats.nodes.forEach(n => {
881888
if (nodes.hasOwnProperty(n.id) && !n.hasOwnProperty('fetching')) {
882889
// no separate fetching stats. that means the runtime is cumulative.
883890
// by subtracting the dependencies from parent runtime we get the runtime per node
884-
nodes[n.id].fetching = 0;
885891
if (parents.hasOwnProperty(n.id)) {
886892
parents[n.id].forEach(pid => {
887-
if (typeof nodes[pid].runtime === 'number') {
888-
nodes[pid].runtime -= n.runtime;
889-
nodes[pid].fetching = 0;
890-
}
893+
nodes[pid].runtime -= n.runtime;
891894
});
892895
}
893896
}
894897
});
895898

896899
stats.nodes.forEach(n => {
897900
if (nodes.hasOwnProperty(n.id)) {
898-
let runtime = n.runtime || 0;
901+
let runtime = 0;
899902
if (n.hasOwnProperty('fetching')) {
903+
// this branch is taken for servers >= 3.12.
904+
runtime = n.runtime;
900905
// we have separate runtime (including fetching time)
901906
// and fetching stats
902907
runtime -= n.fetching;
908+
} else if (nodes[n.id].hasOwnProperty('runtime')) {
909+
// this branch is taken for servers <= 3.11 and can be removed
910+
// eventually.
911+
runtime = nodes[n.id].runtime;
903912
}
913+
904914
nodes[n.id].calls = String(n.calls || 0);
905915
nodes[n.id].parallel = (nodes[n.id].isAsyncPrefetchEnabled ? String(n.parallel || 0) : '-');
906916
nodes[n.id].items = String(n.items || 0);

0 commit comments

Comments
 (0)