10000 disallow subqueries in AQL traversal PRUNE conditions by jsteemann · Pull Request #10232 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

disallow subqueries in AQL traversal PRUNE conditions #10232

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 3 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations 10000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
disallow subqueries in AQL traversal PRUNE conditions
  • Loading branch information
jsteemann committed Oct 11, 2019
commit cbc53e1f57e3a72c1907cda71b34faea898bc2d6
17 changes: 17 additions & 0 deletions arangod/Aql/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,23 @@ AstNode* Ast::createNodeReference(Variable const* variable) {
return node;
}

/// @brief create an AST subquery reference node
AstNode* Ast::createNodeSubqueryReference(std::string const& variableName) {
AstNode* node = createNode(NODE_TYPE_REFERENCE);
node->setFlag(AstNodeFlagType::FLAG_SUBQUERY_REFERENCE);

auto variable = _scopes.getVariable(variableName);

if (variable == nullptr) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"variable not found in reference AstNode");
}

node->setData(variable);

return node;
}

/// @brief create an AST variable access
AstNode* Ast::createNodeAccess(Variable const* variable,
std::vector<basics::AttributeName> const& field) {
Expand Down
3 changes: 3 additions & 0 deletions arangod/Aql/Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class Ast {
/// @brief create an AST reference node
AstNode* createNodeReference(Variable const* variable);

/// @brief create an AST subquery reference node
AstNode* createNodeSubqueryReference(std::string const& variableName);

/// @brief create an AST parameter node for a value literal
AstNode* createNodeParameter(char const* name, size_t length);

Expand Down
1 change: 1 addition & 0 deletions arangod/Aql/AstNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum AstNodeFlagType : AstNodeFlagsType {
FLAG_BIND_PARAMETER = 0x0020000, // node was created from a bind parameter
FLAG_FINALIZED = 0x0040000, // node has been finalized and should not be modified; only
// set and checked in maintainer mode
FLAG_SUBQUERY_REFERENCE = 0x0080000, // node references a subquery
};

/// @brief enumeration of AST node value types
Expand Down
12 changes: 10 additions & 2 deletions arangod/Aql/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ prune_and_options:
node->addMember($2);
// Options
node->addMember($4);

}
;

Expand Down Expand Up @@ -711,6 +710,15 @@ for_statement:
} prune_and_options {
auto graphInfoNode = static_cast<AstNode*>(parser->popStack());
auto variablesNode = static_cast<AstNode*>(parser->popStack());

auto prune = graphInfoNode->getMember(3);
if (prune != nullptr) {
Ast::traverseReadOnly(prune, [&](AstNode const* node) {
if (node->type == NODE_TYPE_REFERENCE && node->hasFlag(AstNodeFlagType::FLAG_SUBQUERY_REFERENCE)) {
parser->registerParseError(TRI_ERROR_QUERY_PARSE, "prune condition must not use a subquery", yylloc.first_line, yylloc.first_column);
}
});
}
auto node = parser->ast()->createNodeTraversal(variablesNode, graphInfoNode);
parser->ast()->addOperation(node);
}
Expand Down Expand Up @@ -1488,7 +1496,7 @@ expression_or_query:
auto subQuery = parser->ast()->createNodeLet(variableName.c_str(), variableName.size(), node, false);
parser->ast()->addOperation(subQuery);

$$ = parser->ast()->createNodeReference(variableName);
$$ = parser->ast()->createNodeSubqueryReference(variableName);
}
;

Expand Down
14 changes: 14 additions & 0 deletions tests/js/server/aql/aql-graph-traverser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,20 @@ function complexFilteringSuite() {

tearDownAll: cleanup,

testPruneWithSubquery: function () {
let query = `FOR v,e,p IN 1..100 OUTBOUND @start @ecol PRUNE 2 <= LENGTH(FOR w IN p.vertices FILTER w._id == v._id RETURN 1) RETURN p`;
try {
let bindVars = {
'@eCol': en,
'start': vertex.Tri1
};
db._query(query, bindVars);
fail();
} catch (err) {
assertEqual(err.errorNum, errors.ERROR_QUERY_PARSE.code);
}
},

testVertexEarlyPruneHighDepth: function () {
var query = `WITH ${vn}
FOR v, e, p IN 100 OUTBOUND @start @@eCol
Expand Down
0