8000 Fix crash in optimizer rule remove-collect-variables by goedderz · Pull Request #14824 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Fix crash in optimizer rule remove-collect-variables #14824

< 8000 /div>
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed unused code
  • Loading branch information
goedderz committed Sep 27, 2021
commit fec41b6fc7fd10f81f25de4779fc9e95ac5c74db
85 changes: 0 additions & 85 deletions arangod/Aql/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2465,91 +2465,6 @@ TopLevelAttributes Ast::getReferencedAttributes(AstNode const* node, bool& isSaf
return result;
}

/// @brief determines the to-be-kept attributes of an INTO expression
std::unordered_set<std::string> Ast::getReferencedAttributesForKeep(
AstNode const* node, Variable const* searchVariable, bool& isSafeForOptimization) {
auto isTargetVariable = [&searchVariable](AstNode const* node) {
if (node->type == NODE_TYPE_INDEXED_ACCESS) {
auto sub = node->getMemberUnchecked(0);
if (sub->type == NODE_TYPE_REFERENCE) {
Variable const* v = static_cast<Variable const*>(sub->getData());
if (v->id == searchVariable->id) {
return true;
}
}
} else if (node->type == NODE_TYPE_EXPANSION) {
if (node->numMembers() < 2) {
return false;
}
auto it = node->getMemberUnchecked(0);
if (it->type != NODE_TYPE_ITERATOR || it->numMembers() != 2) {
return false;
}

auto sub1 = it->getMember(0);
auto sub2 = it->getMember(1);
if (sub1->type != NODE_TYPE_VARIABLE || sub2->type != NODE_TYPE_REFERENCE) {
return false;
}
Variable const* v = static_cast<Variable const*>(sub2->getData());
if (v->id == searchVariable->id) {
return true;
}
}

return false;
};

std::unordered_set<std::string> result;
isSafeForOptimization = true;

auto visitor = [&isSafeForOptimization,
&result, &isTargetVariable,
&searchVariable](AstNode const* node) {
if (!isSafeForOptimization) {
return false;
}

if (node->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
while (node->getMemberUnchecked(0)->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
node = node->getMemberUnchecked(0);
}
if (isTargetVariable(node->getMemberUnchecked(0))) {
result.emplace(node->getString());
// do not descend further
return false;
}
} else if (node->type == NODE_TYPE_REFERENCE) {
Variable const* v = static_cast<Variable const*>(node->getData());
if (v->id == searchVariable->id) {
isSafeForOptimization = false;
return false;
}
} else if (node->type == NODE_TYPE_EXPANSION) {
if (isTargetVariable(node)) {
auto sub = node->getMemberUnchecked(1);
if (sub->type == NODE_TYPE_EXPANSION) {
sub = sub->getMemberUnchecked(0)->getMemberUnchecked(1);
}
if (sub->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
while (sub->getMemberUnchecked(0)->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
sub = sub->getMemberUnchecked(0);
}
result.emplace(sub->getString());
// do not descend further
return false;
}
}
}

return true;
};

traverseReadOnly(node, visitor, ::doNothingVisitor);

return result;
}

/// @brief determines the top-level attributes referenced in an expression for
/// the specified out variable
bool Ast::getReferencedAttributes(AstNode const* node, Variable const* variable,
Expand Down
3 changes: 0 additions & 3 deletions arangod/Aql/Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,6 @@ class Ast {
static bool getReferencedAttributesRecursive(AstNode const*, Variable const*,
std::unordered_set<arangodb::aql::AttributeNamePath>&);

static std::unordered_set<std::string> getReferencedAttributesForKeep(
AstNode const*, Variable const* searchVariable, bool&);

/// @brief replace an attribute access with just the variable
static AstNode* replaceAttributeAccess(AstNode* node, Variable const* variable,
std::vector<std::string> const& attributeName);
Expand Down
0