1
0
Fork 0

fix const-ness so the condition can be modiefied

This commit is contained in:
Jan Christoph Uhde 2016-12-05 16:21:21 +01:00
parent c84223d598
commit 5aabbb0ac0
1 changed files with 16 additions and 14 deletions

View File

@ -4116,12 +4116,12 @@ bool applyGeoOptimization(bool near, ExecutionPlan* plan, GeoIndexInfo& info){
return true; return true;
}; };
AstNode const* isValueOrRefNode(AstNode const* node){ AstNode* isValueOrRefNode(AstNode* node){
//TODO - implement me //TODO - implement me
return node; return node;
} }
GeoIndexInfo isDistanceFunction(AstNode const* node, bool inSubCondition){ GeoIndexInfo isDistanceFunction(AstNode* node, bool inSubCondition){
// the expression must exist and it must be a function call // the expression must exist and it must be a function call
auto rv = GeoIndexInfo{}; auto rv = GeoIndexInfo{};
if(node->type != NODE_TYPE_FCALL) { if(node->type != NODE_TYPE_FCALL) {
@ -4142,17 +4142,17 @@ GeoIndexInfo isDistanceFunction(AstNode const* node, bool inSubCondition){
return rv; return rv;
} }
GeoIndexInfo iterativePreorderWithCondition(AstNode const* root, GeoIndexInfo(*condition)(AstNode const*, bool)){ GeoIndexInfo iterativePreorderWithCondition(AstNode* root, GeoIndexInfo(*condition)(AstNode*, bool)){
// returns on first hit // returns on first hit
if (!root){ if (!root){
return GeoIndexInfo{}; return GeoIndexInfo{};
} }
bool inSubCondition = false; bool inSubCondition = false;
std::vector<AstNode const*> nodestack; std::vector<AstNode*> nodestack;
nodestack.push_back(root); nodestack.push_back(root);
while(nodestack.size()){ while(nodestack.size()){
AstNode const* current = nodestack.back(); AstNode* current = nodestack.back();
nodestack.pop_back(); nodestack.pop_back();
GeoIndexInfo rv = condition(current,inSubCondition); GeoIndexInfo rv = condition(current,inSubCondition);
inSubCondition = true; // only false for root inSubCondition = true; // only false for root
@ -4169,7 +4169,7 @@ GeoIndexInfo iterativePreorderWithCondition(AstNode const* root, GeoIndexInfo(*c
return GeoIndexInfo{}; return GeoIndexInfo{};
} }
GeoIndexInfo isGeoFilterExpression(AstNode const* node, bool inSubCondition){ GeoIndexInfo isGeoFilterExpression(AstNode* node, bool inSubCondition){
// binary compare must be on top // binary compare must be on top
bool dist_first = true; bool dist_first = true;
bool lessEqual = true; bool lessEqual = true;
@ -4197,12 +4197,13 @@ GeoIndexInfo isGeoFilterExpression(AstNode const* node, bool inSubCondition){
} }
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "operator has 2 members"; //LOG_TOPIC(DEBUG, Logger::DEVEL) << "operator has 2 members";
auto first = node->getMember(0);
auto second = node->getMember(1); AstNode* first = node->getMember(0);
AstNode* second = node->getMember(1); //FIXME -- const node
node->dump(0); node->dump(0);
auto eval_stuff = [](bool dist_first, bool lessEqual, GeoIndexInfo&& dist_fun, AstNode const* value_node){ auto eval_stuff = [](bool dist_first, bool lessEqual, GeoIndexInfo&& dist_fun, AstNode* value_node){
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "1: " << dist_first; //LOG_TOPIC(DEBUG, Logger::DEVEL) << "1: " << dist_first;
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "2: " << (bool)dist_fun; //LOG_TOPIC(DEBUG, Logger::DEVEL) << "2: " << (bool)dist_fun;
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "3: " << (bool)value_node; //LOG_TOPIC(DEBUG, Logger::DEVEL) << "3: " << (bool)value_node;
@ -4217,6 +4218,7 @@ GeoIndexInfo isGeoFilterExpression(AstNode const* node, bool inSubCondition){
return dist_fun; return dist_fun;
}; };
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "frist check"; //LOG_TOPIC(DEBUG, Logger::DEVEL) << "frist check";
rv = eval_stuff(dist_first, lessEqual, isDistanceFunction(first, inSubCondition), isValueOrRefNode(second)); rv = eval_stuff(dist_first, lessEqual, isDistanceFunction(first, inSubCondition), isValueOrRefNode(second));
if (!rv) { if (!rv) {
@ -4238,7 +4240,7 @@ GeoIndexInfo identifyGeoOptimizationCandidate(ExecutionNode::NodeType type, Exec
case EN::SORT: { case EN::SORT: {
LOG_TOPIC(DEBUG, Logger::DEVEL) << "found sort node"; LOG_TOPIC(DEBUG, Logger::DEVEL) << "found sort node";
auto node = static_cast<SortNode*>(n); auto node = static_cast<SortNode*>(n);
auto const& elements = node->getElements(); auto& elements = node->getElements();
// we're looking for "SORT DISTANCE(x,y,a,b) ASC", which has just one sort criterion // we're looking for "SORT DISTANCE(x,y,a,b) ASC", which has just one sort criterion
if ( !(elements.size() == 1 && elements[0].second)) { if ( !(elements.size() == 1 && elements[0].second)) {
@ -4247,7 +4249,7 @@ GeoIndexInfo identifyGeoOptimizationCandidate(ExecutionNode::NodeType type, Exec
} }
//variable of sort expression //variable of sort expression
auto const variable = elements[0].first; auto variable = elements[0].first;
TRI_ASSERT(variable != nullptr); TRI_ASSERT(variable != nullptr);
//// find the expression that is bound to the variable //// find the expression that is bound to the variable
@ -4283,14 +4285,14 @@ GeoIndexInfo identifyGeoOptimizationCandidate(ExecutionNode::NodeType type, Exec
// 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 expression = cn->expression();
// the expression must exist and it must have an astNode // the expression must exist and it must have an astNode
if (expression == nullptr || expression->node() == nullptr){ if (expression == nullptr || expression->node() == nullptr){
// not the right type of node // not the right type of node
return rv; return rv;
} }
AstNode const* node = expression->node(); AstNode* node = expression->nodeForModification();
LOG_TOPIC(DEBUG, Logger::DEVEL) << "checking expression of calcaulation"; LOG_TOPIC(DEBUG, Logger::DEVEL) << "checking expression of calcaulation";
@ -4322,7 +4324,7 @@ void checkNodesForGeoOptimization(ExecutionNode::NodeType type, ExecutionPlan* p
SmallVector<ExecutionNode*>::allocator_type::arena_type a; SmallVector<ExecutionNode*>::allocator_type::arena_type a;
SmallVector<ExecutionNode*> nodes{a}; SmallVector<ExecutionNode*> nodes{a};
plan->findNodesOfType(nodes, type, true); plan->findNodesOfType(nodes, type, true);
for (auto const& n : nodes) { for (auto& n : nodes) {
auto geoIndexInfo = identifyGeoOptimizationCandidate(type, plan, n); auto geoIndexInfo = identifyGeoOptimizationCandidate(type, plan, n);
if(!geoIndexInfo){ if(!geoIndexInfo){
continue; continue;