8000 Fixed issue #14807; added regression tests and CHANGELOG entry · arangodb/arangodb@93d5c60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93d5c60

Browse files
committed
Fixed issue #14807; added regression tests and CHANGELOG entry
1 parent 9b489d2 commit 93d5c60

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
v3.7.15 (XXXX-XX-XX)
22
--------------------
33

4+
* Fix issue #14807: Fix crash during optimization of certain AQL queries during
5+
the removeCollectVariables optimizer rule, when a COLLECT node without output
6+
variables (this includes RETURN DISTINCT) occured in the plan.
7+
48
* Fixed a bug for array indexes on update of documents (BTS-548).
59

610
* Fix active failover, so that the new host actually has working foxx services

arangod/Aql/OptimizerRules.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ void arangodb::aql::removeCollectVariablesRule(Optimizer* opt,
12501250
auto collectNode = ExecutionNode::castTo<CollectNode*>(n);
12511251
TRI_ASSERT(collectNode != nullptr);
12521252

1253-
auto const& varsUsedLater = n->getVarsUsedLater();
1253+
auto const& varsUsedLater = collectNode->getVarsUsedLater();
12541254
auto outVariable = collectNode->outVariable();
12551255

12561256
if (outVariable != nullptr &&
@@ -1294,27 +1294,17 @@ void arangodb::aql::removeCollectVariablesRule(Optimizer* opt,
12941294
}
12951295

12961296
} // end - expression exists
1297-
} else if (planNode->getType() == EN::COLLECT) {
1298-
auto innerCollectNode = ExecutionNode::castTo<CollectNode const*>(planNode);
1299-
if (innerCollectNode->hasOutVariable()) {
1300-
// We have the following situation:
1301-
//
1302-
// COLLECT v1 = doc._id INTO g1
1303-
// COLLECT v2 = doc._id INTO g2
1304-
//
1305-
searchVariables.push_back(innerCollectNode->outVariable());
1306-
} else {
1307-
// when we find another COLLECT, it will invalidate all
1308-
// previous variables in the scope
1309-
searchVariables.clear();
1310-
}
13111297
} else {
13121298
auto here = planNode->getVariableIdsUsedHere();
1299+
TRI_ASSERT(!searchVariables.empty());
13131300
if (here.find(searchVariables.back()->id) != here.end()) {
13141301
// the outVariable of the last collect should not be used by any following node directly
13151302
doOptimize = false;
13161303
break;
13171304
}
1305+
if (planNode->getType() == EN::COLLECT) {
1306+
break;
1307+
}
13181308
}
13191309

13201310
planNode = planNode->getFirstParent();

tests/js/server/aql/aql-optimizer-rule-remove-collect-variables.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,42 @@ function optimizerRuleTestSuite () {
357357
assertNotEqual(-1, explain.plan.rules.indexOf(ruleName));
358358
},
359359

360+
// Regression test for https://github.com/arangodb/arangodb/issues/14807.
361+
// This resulted in an invalid memory access in the removeCollectVariablesRule.
362+
testIssue14807 : function () {
363+
const query = `
364+
for u in union([],[])
365+
collect test = u.v into g
366+
return Distinct {
367+
Test: test,
368+
Prop1: MIN(g[*].u.someProp),
369+
Prop2: MAX(g[*].u.someProp)
370+
}
371+
`;
372+
373+
const expectedResults = [];
374+
375+
const results = AQL_EXECUTE(query);
376+
assertEqual(expectedResults, results.json);
377+
},
378+
379+
testCollectIntoBeforeCollectWithoutInto : function () {
380+
const query = `
381+
LET items = [{_id: 'ID'}]
382+
FOR item1 IN items
383+
COLLECT unused1 = item1._id INTO first
384+
COLLECT unused2 = first[0].item1._id
385+
RETURN unused2
386+
`;
387+
const expected = [ "ID" ];
388+
389+
let resultEnabled = AQL_EXECUTE(query, { }, paramEnabled).json;
390+
assertEqual(expected, resultEnabled);
391+
392+
let explain = AQL_EXPLAIN(query, { }, paramEnabled);
393+
assertNotEqual(-1, explain.plan.rules.indexOf(ruleName));
394+
},
395+
360396
};
361397
}
362398

0 commit comments

Comments
 (0)
0