mirror of https://gitee.com/bigwinds/arangodb
now inspect sort and filter nodes
This commit is contained in:
parent
5dbf5e14e3
commit
e619ef3e4e
|
@ -3959,6 +3959,9 @@ std::unique_ptr<Condition> buildGeoCondition(ExecutionPlan* plan, GeoIndexInfo&
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// GEO RULES //////////////////////////////////////////////////////////////////
|
||||||
// TODO - remove debug code
|
// TODO - remove debug code
|
||||||
#ifdef OBIDEBUG
|
#ifdef OBIDEBUG
|
||||||
#define OBILEVEL ERR
|
#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){
|
AstNode const* identifyGeoOptimizationCandidate(ExecutionNode::NodeType type, ExecutionPlan* plan, ExecutionNode* n){
|
||||||
if(sort){
|
ExecutionNode* setter = nullptr;
|
||||||
|
|
||||||
|
switch(type){
|
||||||
|
case EN::SORT: {
|
||||||
auto node = static_cast<SortNode*>(n);
|
auto node = static_cast<SortNode*>(n);
|
||||||
auto const& elements = node->getElements();
|
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
|
//// find the expression that is bound to the variable
|
||||||
// get the expression node that holds the cacluation
|
// get the expression node that holds the cacluation
|
||||||
auto setter = plan->getVarSetBy(variable->id);
|
setter = plan->getVarSetBy(variable->id);
|
||||||
if (setter == nullptr || setter->getType() != EN::CALCULATION) {
|
}
|
||||||
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setter == nullptr || setter->getType() != EN::CALCULATION) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
// downcast to calculation node and get expression
|
// downcast to calculation node and get expression
|
||||||
auto cn = static_cast<CalculationNode*>(setter);
|
auto cn = static_cast<CalculationNode*>(setter);
|
||||||
auto const expression = cn->expression();
|
auto const expression = cn->expression();
|
||||||
|
@ -4131,28 +4156,18 @@ AstNode const* identifyGeoOptimizationCandidate(bool sort, ExecutionPlan* plan,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return funcNode;
|
return funcNode;
|
||||||
} else {
|
|
||||||
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void checkNodesForGeoOptimization(ExecutionNode::NodeType type, ExecutionPlan* plan, bool& modified){
|
||||||
void arangodb::aql::optimizeGeoIndexRule(Optimizer* opt,
|
|
||||||
ExecutionPlan* plan,
|
|
||||||
Optimizer::Rule const* rule) {
|
|
||||||
|
|
||||||
LOG(OBILEVEL) << "ENTER GEO RULE";
|
|
||||||
|
|
||||||
SmallVector<ExecutionNode*>::allocator_type::arena_type a;
|
SmallVector<ExecutionNode*>::allocator_type::arena_type a;
|
||||||
SmallVector<ExecutionNode*> nodes{a};
|
SmallVector<ExecutionNode*> nodes{a};
|
||||||
bool modified = false;
|
|
||||||
|
|
||||||
plan->findNodesOfType(nodes, EN::SORT, true);
|
plan->findNodesOfType(nodes, EN::SORT, true);
|
||||||
|
|
||||||
for (auto const& n : nodes) {
|
for (auto const& n : nodes) {
|
||||||
auto funcNode = identifyGeoOptimizationCandidate(true, plan, n);
|
auto funcNode = identifyGeoOptimizationCandidate(EN::SORT, plan, n);
|
||||||
if(!funcNode){
|
if(!funcNode){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -4161,6 +4176,17 @@ void arangodb::aql::optimizeGeoIndexRule(Optimizer* opt,
|
||||||
modified = true;
|
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);
|
opt->addPlan(plan, rule, modified);
|
||||||
|
|
||||||
LOG(OBILEVEL) << "EXIT GEO RULE";
|
LOG(OBILEVEL) << "EXIT GEO RULE";
|
||||||
|
|
Loading…
Reference in New Issue