8000 fixed issue #2026 · saliormoon/arangodb@b7be5d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7be5d5

Browse files
committed
fixed issue arangodb#2026
1 parent 1c34b56 commit b7be5d5

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ devel
4848
v3.0.6 (XXXX-XX-XX)
4949
-------------------
5050

51+
* fixed issue #2026
52+
5153
* slightly better error diagnostics for AQL query compilation and replication
5254

5355
* fixed issue #2018

arangod/Aql/CollectNode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ struct UserVarFinder final : public WalkerWorker<ExecutionNode> {
192192
en->getType() == ExecutionNode::INDEX ||
193193
en->getType() == ExecutionNode::ENUMERATE_LIST ||
194194
en->getType() == ExecutionNode::TRAVERSAL ||
195+
en->getType() == ExecutionNode::SHORTEST_PATH ||
195196
en->getType() == ExecutionNode::COLLECT) {
196197
depth += 1;
197198
}

arangod/Aql/ExecutionNode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ ExecutionNode const* ExecutionNode::getLoop() const {
581581
auto type = node->getType();
582582

583583
if (type == ENUMERATE_COLLECTION || type == INDEX || type == TRAVERSAL ||
584-
type == ENUMERATE_LIST) {
584+
type == ENUMERATE_LIST || type == SHORTEST_PATH) {
585585
return node;
586586
}
587587
}
@@ -1147,7 +1147,7 @@ void ExecutionNode::RegisterPlan::after(ExecutionNode* en) {
11471147
en->getVarsUsedLater();
11481148
std::vector<Variable const*> const& varsUsedHere =
11491149
en->getVariablesUsedHere();
1150-
1150+
11511151
// We need to delete those variables that have been used here but are not
11521152
// used any more later:
11531153
std::unordered_set<RegisterId> regsToClear;
@@ -1160,7 +1160,7 @@ void ExecutionNode::RegisterPlan::after(ExecutionNode* en) {
11601160

11611161
if (it2 == varInfo.end()) {
11621162
// report an error here to prevent crashing
1163-
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "missing variable #" + std::to_string(v->id) + " for node " + en->getTypeString() + " while planning registers");
1163+
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "missing variable #" + std::to_string(v->id) + " (" + v->name + ") for node " + en->getTypeString() + " while planning registers");
11641164
}
11651165

11661166
// finally adjust the variable inside the IN calculation

arangod/Aql/ExecutionPlan.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ ExecutionNode* ExecutionPlan::fromNodeTraversal(ExecutionNode* previous,
749749
return addDependency(previous, en);
750750
}
751751

752-
AstNode const* ExecutionPlan::parseTraversalVertexNode(ExecutionNode* previous,
752+
AstNode const* ExecutionPlan::parseTraversalVertexNode(ExecutionNode*& previous,
753753
AstNode const* vertex) {
754754
if (vertex->type == NODE_TYPE_OBJECT && vertex->isConstant()) {
755755
size_t n = vertex->numMembers();
@@ -767,6 +767,8 @@ AstNode const* ExecutionPlan::parseTraversalVertexNode(ExecutionNode* previous,
767767
// operand is some misc expression
768768
auto calc = createTemporaryCalculation(vertex, previous);
769769
vertex = _ast->createNodeReference(getOutVariable(calc));
770+
// update previous so the caller has an updated value
771+
previous = calc;
770772
}
771773

772774
return vertex;
@@ -1960,6 +1962,7 @@ bool ExecutionPlan::isDeadSimple() const {
19601962
nodeType == ExecutionNode::ENUMERATE_COLLECTION ||
19611963
nodeType == ExecutionNode::ENUMERATE_LIST ||
19621964
nodeType == ExecutionNode::TRAVERSAL ||
1965+
nodeType == ExecutionNode::SHORTEST_PATH ||
19631966
nodeType == ExecutionNode::INDEX) {
19641967
// these node types are not simple
19651968
return false;

arangod/Aql/ExecutionPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class ExecutionPlan {
286286
ExecutionNode* fromJson(arangodb::basics::Json const& Json);
287287

288288
/// @brief create an vertex element for graph nodes
289-
AstNode const* parseTraversalVertexNode(ExecutionNode*, AstNode const*);
289+
AstNode const* parseTraversalVertexNode(ExecutionNode*&, AstNode const*);
290290

291291
private:
292292
/// @brief map from node id to the actual node

arangod/Aql/OptimizerRules.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "Aql/Function.h"
3333
#include "Aql/IndexNode.h"
3434
#include "Aql/ModificationNodes.h"
35+
#include "Aql/ShortestPathNode.h"
3536
#include "Aql/SortCondition.h"
3637
#include "Aql/SortNode.h"
3738
#include "Aql/TraversalConditionFinder.h"
@@ -324,7 +325,8 @@ void arangodb::aql::removeRedundantSortsRule(Optimizer* opt,
324325
}
325326
} else if (current->getType() == EN::ENUMERATE_LIST ||
326327
current->getType() == EN::ENUMERATE_COLLECTION ||
327-
current->getType() == EN::TRAVERSAL) {
328+
current->getType() == EN::TRAVERSAL ||
329+
current->getType() == EN::SHORTEST_PATH) {
328330
// ok, but we cannot remove two different sorts if one of these node
329331
// types is between them
330332
// example: in the following query, the one sort will be optimized
@@ -764,10 +766,10 @@ void arangodb::aql::removeSortRandRule(Optimizer* opt, ExecutionPlan* plan,
764766
case EN::SUBQUERY:
765767
case EN::ENUMERATE_LIST:
766768
case EN::TRAVERSAL:
769+
case EN::SHORTEST_PATH:
767770
case EN::INDEX: {
768-
// if we found another SortNode, an CollectNode, FilterNode, a
769-
// SubqueryNode,
770-
// an EnumerateListNode, a TraversalNode or an IndexNode
771+
// if we found another SortNode, a CollectNode, FilterNode, a
772+
// SubqueryNode, an EnumerateListNode, a TraversalNode or an IndexNode
771773
// this means we cannot apply our optimization
772774
collectionNode = nullptr;
773775
current = nullptr;
@@ -949,7 +951,9 @@ void arangodb::aql::moveCalculationsDownRule(Optimizer* opt,
949951
} else if (currentType == EN::INDEX ||
950952
currentType == EN::ENUMERATE_COLLECTION ||
951953
currentType == EN::ENUMERATE_LIST ||
952-
currentType == EN::TRAVERSAL || currentType == EN::COLLECT ||
954+
currentType == EN::TRAVERSAL ||
955+
currentType == EN::SHORTEST_PATH ||
956+
currentType == EN::COLLECT ||
953957
currentType == EN::NORESULTS) {
954958
// we will not push further down than such nodes
955959
shouldMove = false;
@@ -1241,6 +1245,17 @@ class arangodb::aql::RedundantCalculationsReplacer final
12411245
std::unordered_map<VariableId, Variable const*> const& replacements)
12421246
: _replacements(replacements) {
12431247
}
1248+
1249+
template <typename T>
1250+
void replaceStartTargetVariables(ExecutionNode* en) {
1251+
auto node = static_cast<T*>(en);
1252+
if (node->_inStartVariable != nullptr) {
1253+
node->_inStartVariable = Variable::replace(node->_inStartVariable, _replacements);
1254+
}
1255+
if (node->_inTargetVariable != nullptr) {
1256+
node->_inTargetVariable = Variable::replace(node->_inTargetVariable, _replacements);
1257+
}
1258+
}
12441259

12451260
template <typename T>
12461261
void replaceInVariable(ExecutionNode* en) {
@@ -1290,6 +1305,11 @@ class arangodb::aql::RedundantCalculationsReplacer final
12901305
replaceInVariable<TraversalNode>(en);
12911306
break;
12921307
}
1308+
1309+
case EN::SHORTEST_PATH: {
1310+
replaceStartTargetVariables<ShortestPathNode>(en);
1311+
break;
1312+
}
12931313

12941314
case EN::COLLECT: {
12951315
auto node = static_cast<CollectNode*>(en);
@@ -3589,7 +3609,7 @@ void arangodb::aql::patchUpdateStatementsRule(Optimizer* opt,
35893609
}
35903610
}
35913611

3592-
if (type == EN::TRAVERSAL) {
3612+
if (type == EN::TRAVERSAL || type == EN::SHORTEST_PATH) {
35933613
// unclear what will be read by the traversal
35943614
modified = false;
35953615
break;

arangod/Aql/ShortestPathNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace aql {
3838
/// @brief class ShortestPathNode
3939
class ShortestPathNode : public ExecutionNode {
4040
friend class ExecutionBlock;
41+
friend class RedundantCalculationsReplacer;
4142
friend class ShortestPathBlock;
4243

4344
/// @brief constructor with a vocbase and a collection name

0 commit comments

Comments
 (0)
0