1
0
Fork 0

now inspect sort and filter nodes

This commit is contained in:
Jan Christoph Uhde 2016-12-01 12:21:51 +01:00
parent 5dbf5e14e3
commit e619ef3e4e
1 changed files with 71 additions and 45 deletions

View File

@ -3959,6 +3959,9 @@ std::unique_ptr<Condition> buildGeoCondition(ExecutionPlan* plan, GeoIndexInfo&
return condition;
}
// GEO RULES //////////////////////////////////////////////////////////////////
// TODO - remove debug code
#ifdef OBIDEBUG
#define OBILEVEL ERR
@ -4089,8 +4092,11 @@ bool applyGeoOptimization(bool near, ExecutionPlan* plan, ExecutionNode* node, A
};
AstNode const* identifyGeoOptimizationCandidate(bool sort, ExecutionPlan* plan, ExecutionNode* n){
if(sort){
AstNode const* identifyGeoOptimizationCandidate(ExecutionNode::NodeType type, ExecutionPlan* plan, ExecutionNode* n){
ExecutionNode* setter = nullptr;
switch(type){
case EN::SORT: {
auto node = static_cast<SortNode*>(n);
auto const& elements = node->getElements();
@ -4105,11 +4111,30 @@ AstNode const* identifyGeoOptimizationCandidate(bool sort, ExecutionPlan* plan,
//// find the expression that is bound to the variable
// get the expression node that holds the cacluation
auto setter = plan->getVarSetBy(variable->id);
if (setter == nullptr || setter->getType() != EN::CALCULATION) {
setter = plan->getVarSetBy(variable->id);
}
break;
case EN::FILTER: {
auto node = static_cast<FilterNode*>(n);
// filter nodes always have one input variable
auto varsUsedHere = node->getVariablesUsedHere();
TRI_ASSERT(varsUsedHere.size() == 1);
// now check who introduced our variable
auto variable = varsUsedHere[0];
setter = plan->getVarSetBy(variable->id);
}
break;
default:
return nullptr;
}
if (setter == nullptr || setter->getType() != EN::CALCULATION) {
return nullptr;
}
// downcast to calculation node and get expression
auto cn = static_cast<CalculationNode*>(setter);
auto const expression = cn->expression();
@ -4131,28 +4156,18 @@ AstNode const* identifyGeoOptimizationCandidate(bool sort, ExecutionPlan* plan,
return nullptr;
}
return funcNode;
} else {
return nullptr;
}
};
void arangodb::aql::optimizeGeoIndexRule(Optimizer* opt,
ExecutionPlan* plan,
Optimizer::Rule const* rule) {
LOG(OBILEVEL) << "ENTER GEO RULE";
void checkNodesForGeoOptimization(ExecutionNode::NodeType type, ExecutionPlan* plan, bool& modified){
SmallVector<ExecutionNode*>::allocator_type::arena_type a;
SmallVector<ExecutionNode*> nodes{a};
bool modified = false;
plan->findNodesOfType(nodes, EN::SORT, true);
for (auto const& n : nodes) {
auto funcNode = identifyGeoOptimizationCandidate(true, plan, n);
auto funcNode = identifyGeoOptimizationCandidate(EN::SORT, plan, n);
if(!funcNode){
continue;
}
@ -4161,6 +4176,17 @@ void arangodb::aql::optimizeGeoIndexRule(Optimizer* opt,
modified = true;
}
}
}
void arangodb::aql::optimizeGeoIndexRule(Optimizer* opt,
ExecutionPlan* plan,
Optimizer::Rule const* rule) {
LOG(OBILEVEL) << "ENTER GEO RULE";
bool modified = false;
checkNodesForGeoOptimization(EN::SORT, plan, modified);
checkNodesForGeoOptimization(EN::FILTER, plan, modified);
opt->addPlan(plan, rule, modified);
LOG(OBILEVEL) << "EXIT GEO RULE";