From 1769299e9536b41c6b549626ae0ef617ce13e4be Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 4 Jul 2016 16:30:04 +0200 Subject: [PATCH] make optimizer not skip "use-indexes-rule", even if enough plans have been created already --- arangod/Aql/AstNode.cpp | 4 ++++ arangod/Aql/Condition.cpp | 8 ++++++++ arangod/Aql/Optimizer.cpp | 10 +++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/arangod/Aql/AstNode.cpp b/arangod/Aql/AstNode.cpp index ab590cf45c..241d24baa1 100644 --- a/arangod/Aql/AstNode.cpp +++ b/arangod/Aql/AstNode.cpp @@ -871,6 +871,10 @@ void AstNode::dump(int level) const { if (type == NODE_TYPE_VALUE || type == NODE_TYPE_ARRAY) { std::unique_ptr json(toJsonValue(TRI_UNKNOWN_MEM_ZONE)); std::cout << ": " << json.get(); + } else if (type == NODE_TYPE_ATTRIBUTE_ACCESS) { + std::cout << ": " << getString(); + } else if (type == NODE_TYPE_REFERENCE) { + std::cout << ": " << static_cast(getData())->name; } std::cout << "\n"; diff --git a/arangod/Aql/Condition.cpp b/arangod/Aql/Condition.cpp index 4c669fd1ac..20eb2565d9 100644 --- a/arangod/Aql/Condition.cpp +++ b/arangod/Aql/Condition.cpp @@ -194,6 +194,14 @@ bool ConditionPart::isCoveredBy(ConditionPart const& other, bool isReversed) con } } + TRI_ASSERT(valueNode != nullptr); + TRI_ASSERT(other.valueNode != nullptr); + + if (!valueNode->isConstant() || !other.valueNode->isConstant()) { + return false; + } + + // special cases for IN... if (!isExpanded && !other.isExpanded && other.operatorType == NODE_TYPE_OPERATOR_BINARY_IN && diff --git a/arangod/Aql/Optimizer.cpp b/arangod/Aql/Optimizer.cpp index b46b9073bc..0fb23971fd 100644 --- a/arangod/Aql/Optimizer.cpp +++ b/arangod/Aql/Optimizer.cpp @@ -146,9 +146,13 @@ int Optimizer::createPlans(ExecutionPlan* plan, level = (*it).first; auto& rule = (*it).second; + // skip over rules if we should + // however, we don't want to skip the "use-indexes" rule when it + // was not explicitly deactivated by the caller if ((runOnlyRequiredRules || disabledIds.find(level) != disabledIds.end()) && - rule.canBeDisabled) { + rule.canBeDisabled && + (!runOnlyRequiredRules || rule.name != "use-indexes")) { // we picked a disabled rule or we have reached the max number of // plans // and just skip this rule @@ -299,7 +303,7 @@ std::unordered_set Optimizer::getDisabledRuleIds( } } else { // disable a specific rule - auto it = _ruleLookup.find(std::string(name.c_str() + 1)); + auto it = _ruleLookup.find(name.c_str() + 1); if (it != _ruleLookup.end()) { disabled.emplace((*it).second); @@ -311,7 +315,7 @@ std::unordered_set Optimizer::getDisabledRuleIds( // enable all rules disabled.clear(); } else { - auto it = _ruleLookup.find(std::string(name.c_str() + 1)); + auto it = _ruleLookup.find(name.c_str() + 1); if (it != _ruleLookup.end()) { disabled.erase((*it).second);