mirror of https://gitee.com/bigwinds/arangodb
activate rule to move calculations up
This commit is contained in:
parent
89e74559ae
commit
a1fcf9b28e
|
@ -964,7 +964,7 @@ void ExecutionPlan::unlinkNodes (std::unordered_set<ExecutionNode*>& toRemove) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ExecutionPlan::unlinkNode (ExecutionNode* node) {
|
void ExecutionPlan::unlinkNode (ExecutionNode* node) {
|
||||||
auto&& parents = node->getParents();
|
auto parents = node->getParents();
|
||||||
if (parents.empty()) {
|
if (parents.empty()) {
|
||||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||||
"Cannot unlink root node of plan.");
|
"Cannot unlink root node of plan.");
|
||||||
|
@ -974,7 +974,7 @@ void ExecutionPlan::unlinkNode (ExecutionNode* node) {
|
||||||
"Cannot remove node with more than one parent.");
|
"Cannot remove node with more than one parent.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto&& dep = node->getDependencies();
|
auto dep = node->getDependencies();
|
||||||
parents[0]->removeDependency(node);
|
parents[0]->removeDependency(node);
|
||||||
for (auto x : dep) {
|
for (auto x : dep) {
|
||||||
parents[0]->addDependency(x);
|
parents[0]->addDependency(x);
|
||||||
|
@ -1000,7 +1000,7 @@ void ExecutionPlan::replaceNode (ExecutionNode* oldNode,
|
||||||
newNode->addDependency(x);
|
newNode->addDependency(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto&& oldNodeParents = oldNode->getParents();
|
auto oldNodeParents = oldNode->getParents();
|
||||||
for (auto oldNodeParent : oldNodeParents) {
|
for (auto oldNodeParent : oldNodeParents) {
|
||||||
if(! oldNodeParent->replaceDependency(oldNode, newNode)){
|
if(! oldNodeParent->replaceDependency(oldNode, newNode)){
|
||||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||||
|
@ -1020,7 +1020,7 @@ void ExecutionPlan::insertDependency (ExecutionNode* oldNode,
|
||||||
TRI_ASSERT(newNode->getDependencies().size() == 1);
|
TRI_ASSERT(newNode->getDependencies().size() == 1);
|
||||||
TRI_ASSERT(oldNode != _root);
|
TRI_ASSERT(oldNode != _root);
|
||||||
|
|
||||||
auto&& oldDeps = oldNode->getDependencies();
|
auto oldDeps = oldNode->getDependencies();
|
||||||
if (! oldNode->replaceDependency(oldDeps[0], newNode)) {
|
if (! oldNode->replaceDependency(oldDeps[0], newNode)) {
|
||||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||||
"Could not replace dependencies of an old node.");
|
"Could not replace dependencies of an old node.");
|
||||||
|
|
|
@ -128,12 +128,6 @@ int triagens::aql::moveCalculationsUpRule (Optimizer* opt,
|
||||||
// (sorting is needed for intersection later)
|
// (sorting is needed for intersection later)
|
||||||
std::sort(neededVars.begin(), neededVars.end(), &Variable::Comparator);
|
std::sort(neededVars.begin(), neededVars.end(), &Variable::Comparator);
|
||||||
|
|
||||||
std::cout << "FOUND A CALCULATIONNODE THAT CANNOT THROW\n";
|
|
||||||
//std::cout << "JSON: " << nn->expression()->toJson(TRI_UNKNOWN_MEM_ZONE, false).toString() << "\n";
|
|
||||||
for (auto x : neededVars) {
|
|
||||||
std::cout << "CALC USES VAR: " << x->name << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ExecutionNode*> stack;
|
std::vector<ExecutionNode*> stack;
|
||||||
for (auto dep : n->getDependencies()) {
|
for (auto dep : n->getDependencies()) {
|
||||||
stack.push_back(dep);
|
stack.push_back(dep);
|
||||||
|
@ -145,15 +139,11 @@ for (auto x : neededVars) {
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
std::cout << "LOOKING AT NODE OF TYPE: " << current->getTypeString() << "\n";
|
|
||||||
std::cout << "FOUND PREDEC NODE OF TYPE " << current->getTypeString() << "\n";
|
|
||||||
|
|
||||||
auto&& varsSet = current->getVariablesSetHere();
|
auto&& varsSet = current->getVariablesSetHere();
|
||||||
for (auto v : varsSet) {
|
for (auto v : varsSet) {
|
||||||
for (auto it = neededVars.begin(); it != neededVars.end(); ++it) {
|
for (auto it = neededVars.begin(); it != neededVars.end(); ++it) {
|
||||||
if ((*it)->id == v->id) {
|
if ((*it)->id == v->id) {
|
||||||
// shared variable, cannot move up any more
|
// shared variable, cannot move up any more
|
||||||
std::cout << "FOUND SHARED VARIABLE: " << v->name << "\n";
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -178,9 +168,9 @@ std::cout << "FOUND PREDEC NODE OF TYPE " << current->getTypeString() << "\n";
|
||||||
|
|
||||||
// first, delete the calculation from the plan
|
// first, delete the calculation from the plan
|
||||||
plan->unlinkNode(n);
|
plan->unlinkNode(n);
|
||||||
|
// and re-insert into before the current node
|
||||||
plan->insertDependency(current, n);
|
plan->insertDependency(current, n);
|
||||||
modified = true;
|
modified = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -201,6 +191,7 @@ int triagens::aql::removeUnnecessaryCalculationsRule (Optimizer* opt,
|
||||||
ExecutionPlan* plan,
|
ExecutionPlan* plan,
|
||||||
Optimizer::PlanList& out,
|
Optimizer::PlanList& out,
|
||||||
bool& keep) {
|
bool& keep) {
|
||||||
|
std::cout << "REMOVE UNNECESSARY CALCULATIONS\n";
|
||||||
keep = true;
|
keep = true;
|
||||||
std::vector<ExecutionNode*> nodes
|
std::vector<ExecutionNode*> nodes
|
||||||
= plan->findNodesOfType(triagens::aql::ExecutionNode::CALCULATION, true);
|
= plan->findNodesOfType(triagens::aql::ExecutionNode::CALCULATION, true);
|
||||||
|
|
Loading…
Reference in New Issue