mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'aql2' of ssh://github.com/triAGENS/ArangoDB into aql2
Conflicts: arangod/Aql/ExecutionBlock.h
This commit is contained in:
commit
5315f35ed3
|
@ -138,6 +138,10 @@ ExecutionEngine* ExecutionEngine::instanciateFromPlan (ExecutionNode* plan) {
|
|||
return engine;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add a block to the engine
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -76,12 +76,6 @@ namespace triagens {
|
|||
|
||||
static ExecutionEngine* instanciateFromPlan (ExecutionNode*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add a block to the engine
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void addBlock (ExecutionBlock*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the root block
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -91,6 +85,18 @@ namespace triagens {
|
|||
return _root;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add a block to the engine
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void addBlock (ExecutionBlock*);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Aql, query plan generator
|
||||
/// @brief Aql, execution plan
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
|
@ -27,7 +27,7 @@
|
|||
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Aql/PlanGenerator.h"
|
||||
#include "Aql/ExecutionPlan.h"
|
||||
#include "Aql/Ast.h"
|
||||
#include "Aql/AstNode.h"
|
||||
#include "Aql/ExecutionNode.h"
|
||||
|
@ -37,23 +37,30 @@
|
|||
#include "Utils/Exception.h"
|
||||
|
||||
using namespace triagens::aql;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create the generator
|
||||
/// @brief create the plan
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PlanGenerator::PlanGenerator () {
|
||||
ExecutionPlan::ExecutionPlan ()
|
||||
: _nodes(),
|
||||
_root(nullptr) {
|
||||
|
||||
_nodes.reserve(8);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief destroy the generator
|
||||
/// @brief destroy the plan, frees all assigned nodes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PlanGenerator::~PlanGenerator () {
|
||||
ExecutionPlan::~ExecutionPlan () {
|
||||
for (auto it = _nodes.begin(); it != _nodes.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -61,30 +68,48 @@ PlanGenerator::~PlanGenerator () {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an initial execution plan from an abstract syntax tree
|
||||
/// @brief create an execution plan from an AST
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromAst (Ast const* ast) {
|
||||
ExecutionPlan* ExecutionPlan::instanciateFromAst (Ast const* ast) {
|
||||
TRI_ASSERT(ast != nullptr);
|
||||
|
||||
|
||||
auto root = ast->root();
|
||||
TRI_ASSERT(root != nullptr);
|
||||
TRI_ASSERT(root->type == NODE_TYPE_ROOT);
|
||||
|
||||
ExecutionNode* plan = fromNode(ast, root);
|
||||
auto plan = new ExecutionPlan();
|
||||
|
||||
return plan;
|
||||
try {
|
||||
plan->_root = plan->fromNode(ast, root);
|
||||
|
||||
return plan;
|
||||
}
|
||||
catch (...) {
|
||||
delete plan;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add a node to the plan
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ExecutionPlan::addNode (ExecutionNode* node) {
|
||||
TRI_ASSERT(node != nullptr);
|
||||
|
||||
_nodes.push_back(node);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a calculation node for an arbitrary expression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CalculationNode* PlanGenerator::createTemporaryCalculation (Ast const* ast,
|
||||
CalculationNode* ExecutionPlan::createTemporaryCalculation (Ast const* ast,
|
||||
AstNode const* expression) {
|
||||
// generate a temporary variable
|
||||
auto out = ast->variables()->createTemporaryVariable();
|
||||
|
@ -108,7 +133,7 @@ CalculationNode* PlanGenerator::createTemporaryCalculation (Ast const* ast,
|
|||
/// @brief adds "previous" as dependency to "plan", returns "plan"
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::addDependency (ExecutionNode* previous,
|
||||
ExecutionNode* ExecutionPlan::addDependency (ExecutionNode* previous,
|
||||
ExecutionNode* plan) {
|
||||
TRI_ASSERT(previous != nullptr);
|
||||
TRI_ASSERT(plan != nullptr);
|
||||
|
@ -128,7 +153,7 @@ ExecutionNode* PlanGenerator::addDependency (ExecutionNode* previous,
|
|||
/// @brief create an execution plan element from an AST FOR node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeFor (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeFor (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_FOR);
|
||||
|
@ -179,7 +204,7 @@ ExecutionNode* PlanGenerator::fromNodeFor (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST FILTER node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeFilter (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeFilter (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_FILTER);
|
||||
|
@ -216,7 +241,7 @@ ExecutionNode* PlanGenerator::fromNodeFilter (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST LET node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeLet (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeLet (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_LET);
|
||||
|
@ -254,7 +279,7 @@ ExecutionNode* PlanGenerator::fromNodeLet (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST SORT node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeSort (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeSort (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_SORT);
|
||||
|
@ -315,7 +340,7 @@ ExecutionNode* PlanGenerator::fromNodeSort (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST COLLECT node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeCollect (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeCollect (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_COLLECT);
|
||||
|
@ -333,7 +358,7 @@ ExecutionNode* PlanGenerator::fromNodeCollect (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST LIMIT node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeLimit (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeLimit (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_LIMIT);
|
||||
|
@ -354,7 +379,7 @@ ExecutionNode* PlanGenerator::fromNodeLimit (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST RETURN node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeReturn (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeReturn (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_RETURN);
|
||||
|
@ -391,7 +416,7 @@ ExecutionNode* PlanGenerator::fromNodeReturn (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST REMOVE node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeRemove (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeRemove (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_REMOVE);
|
||||
|
@ -406,7 +431,7 @@ ExecutionNode* PlanGenerator::fromNodeRemove (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST INSERT node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeInsert (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeInsert (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_INSERT);
|
||||
|
@ -421,7 +446,7 @@ ExecutionNode* PlanGenerator::fromNodeInsert (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST UPDATE node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeUpdate (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeUpdate (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_UPDATE);
|
||||
|
@ -436,7 +461,7 @@ ExecutionNode* PlanGenerator::fromNodeUpdate (Ast const* ast,
|
|||
/// @brief create an execution plan element from an AST REPLACE node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNodeReplace (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNodeReplace (Ast const* ast,
|
||||
ExecutionNode* previous,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr && node->type == NODE_TYPE_REPLACE);
|
||||
|
@ -451,7 +476,7 @@ ExecutionNode* PlanGenerator::fromNodeReplace (Ast const* ast,
|
|||
/// @brief create an execution plan from an abstract syntax tree node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* PlanGenerator::fromNode (Ast const* ast,
|
||||
ExecutionNode* ExecutionPlan::fromNode (Ast const* ast,
|
||||
AstNode const* node) {
|
||||
TRI_ASSERT(node != nullptr);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Aql, query plan generator
|
||||
/// @brief Aql, execution plan
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
|
@ -27,8 +27,8 @@
|
|||
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGODB_AQL_PLAN_GENERATOR_H
|
||||
#define ARANGODB_AQL_PLAN_GENERATOR_H 1
|
||||
#ifndef ARANGODB_AQL_EXECUTION_PLAN_H
|
||||
#define ARANGODB_AQL_EXECUTION_PLAN_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
|
||||
|
@ -41,28 +41,30 @@ namespace triagens {
|
|||
class ExecutionNode;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class PlanGenerator
|
||||
// --SECTION-- class ExecutionPlan
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class PlanGenerator {
|
||||
class ExecutionPlan {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create the plan
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionPlan ();
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create the generator
|
||||
/// @brief destroy the plan, frees all assigned nodes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PlanGenerator ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief destroy the generator
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
~PlanGenerator ();
|
||||
~ExecutionPlan ();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public methods
|
||||
|
@ -71,10 +73,19 @@ namespace triagens {
|
|||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an initial execution plan from an abstract syntax tree
|
||||
/// @brief create an execution plan from an AST
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* fromAst (Ast const*);
|
||||
static ExecutionPlan* instanciateFromAst (Ast const*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the root node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* root () const {
|
||||
TRI_ASSERT(_root != nullptr);
|
||||
return _root;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private methods
|
||||
|
@ -82,6 +93,12 @@ namespace triagens {
|
|||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add a node to the plan
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void addNode (ExecutionNode*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a calculation node for an arbitrary expression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -191,12 +208,25 @@ namespace triagens {
|
|||
ExecutionNode* fromNode (Ast const*,
|
||||
AstNode const*);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief all nodes registered, used for memory management
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::vector<ExecutionNode*> _nodes;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief root node of the engine
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExecutionNode* _root;
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -29,8 +29,8 @@
|
|||
|
||||
#include "Aql/Query.h"
|
||||
#include "Aql/ExecutionBlock.h"
|
||||
#include "Aql/ExecutionPlan.h"
|
||||
#include "Aql/Parser.h"
|
||||
#include "Aql/PlanGenerator.h"
|
||||
#include "Aql/V8Executor.h"
|
||||
#include "Aql/ExecutionEngine.h"
|
||||
#include "BasicsC/json.h"
|
||||
|
@ -173,8 +173,7 @@ QueryResult Query::execute () {
|
|||
parser.ast()->injectBindParameters(_bindParameters);
|
||||
parser.ast()->optimize();
|
||||
|
||||
PlanGenerator generator;
|
||||
auto plan = generator.fromAst(parser.ast());
|
||||
auto plan = ExecutionPlan::instanciateFromAst(parser.ast());
|
||||
|
||||
try {
|
||||
auto exec = ExecutionEngine::instanciateFromPlan(plan);
|
||||
|
|
|
@ -63,10 +63,10 @@ add_executable(
|
|||
Aql/ExecutionBlock.cpp
|
||||
Aql/ExecutionEngine.cpp
|
||||
Aql/ExecutionNode.cpp
|
||||
Aql/ExecutionPlan.cpp
|
||||
Aql/Expression.cpp
|
||||
Aql/grammar.cpp
|
||||
Aql/Parser.cpp
|
||||
Aql/PlanGenerator.cpp
|
||||
Aql/Query.cpp
|
||||
Aql/Scopes.cpp
|
||||
Aql/Types.cpp
|
||||
|
|
|
@ -44,10 +44,10 @@ arangod_libarangod_a_SOURCES = \
|
|||
arangod/Aql/ExecutionBlock.cpp \
|
||||
arangod/Aql/ExecutionEngine.cpp \
|
||||
arangod/Aql/ExecutionNode.cpp \
|
||||
arangod/Aql/ExecutionPlan.cpp \
|
||||
arangod/Aql/Expression.cpp \
|
||||
arangod/Aql/grammar.cpp \
|
||||
arangod/Aql/Parser.cpp \
|
||||
arangod/Aql/PlanGenerator.cpp \
|
||||
arangod/Aql/Query.cpp \
|
||||
arangod/Aql/Scopes.cpp \
|
||||
arangod/Aql/Types.cpp \
|
||||
|
|
|
@ -34,8 +34,10 @@
|
|||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-explain.h"
|
||||
#include "Ahuacatl/ahuacatl-result.h"
|
||||
#include "Aql/ExecutionNode.h"
|
||||
#include "Aql/ExecutionBlock.h"
|
||||
#include "Aql/ExecutionNode.h"
|
||||
#include "Aql/ExecutionPlan.h"
|
||||
#include "Aql/ExecutionEngine.h"
|
||||
#include "Aql/Query.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/Utf8Helper.h"
|
||||
|
|
Loading…
Reference in New Issue