diff --git a/arangod/Aql/ExecutionPlan.cpp b/arangod/Aql/ExecutionPlan.cpp new file mode 100644 index 0000000000..cc5ef89d42 --- /dev/null +++ b/arangod/Aql/ExecutionPlan.cpp @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief Infrastructure for ExecutionPlans +/// +/// @file arangod/Aql/ExecutionPlan.h +/// +/// DISCLAIMER +/// +/// Copyright 2010-2014 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Max Neunhoeffer +/// @author Copyright 2014, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "Aql/ExecutionPlan.h" + +using namespace triagens::aql; + +// ----------------------------------------------------------------------------- +// --SECTION-- methods of ExecutionPlan +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief toJson, export an ExecutionPlan to JSON +//////////////////////////////////////////////////////////////////////////////// + +TRI_json_t* ExecutionPlan::toJson (TRI_memory_zone_t* zone) { + TRI_json_t* json = TRI_CreateArray2Json(zone, 1); + TRI_json_t* sub = TRI_CreateStringCopyJson(zone, "ILLEGAL"); + TRI_Insert2ArrayJson(zone, json, "type", sub); + return json; +} + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: + + diff --git a/arangod/Aql/ExecutionPlan.h b/arangod/Aql/ExecutionPlan.h new file mode 100644 index 0000000000..1088430e0f --- /dev/null +++ b/arangod/Aql/ExecutionPlan.h @@ -0,0 +1,180 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief Infrastructure for ExecutionPlans +/// +/// @file arangod/Aql/ExecutionPlan.h +/// +/// DISCLAIMER +/// +/// Copyright 2010-2014 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Max Neunhoeffer +/// @author Copyright 2014, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGODB_AQL_EXECUTION_PLAN_H +#define ARANGODB_AQL_EXECUTION_PLAN_H 1 + +#include + +#include + +namespace triagens { + namespace aql { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief class ExecutionPlan, abstract base class +//////////////////////////////////////////////////////////////////////////////// + + class ExecutionPlan { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief node type +//////////////////////////////////////////////////////////////////////////////// + + public: + + enum NodeType { + ILLEGAL, + ENUMERATE_COLLECTION, + INDEX_RANGE, + STATIC_LIST, + FILTER, + LIMIT, + INTERSECTION, + PROJECTION, + CALCULATION, + SORT, + AGGREGATE_ON_SORTED, + AGGREGATE_ON_UNSORTED, + LOOKUP_JOIN, + MERGE_JOIN, + LOOKUP_INDEX_UNIQUE, + LOOKUP_INDEX_RANGE, + LOOKUP_FULL_COLLECTION, + CONCATENATION, + MERGE, + REMOTE, + INSERT, + REMOVE, + REPLACE, + UPDATE, + ROOT + }; + +// ----------------------------------------------------------------------------- +// --SECTION-- public methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief default constructor +//////////////////////////////////////////////////////////////////////////////// + + ExecutionPlan () { + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief constructor with one dependency +//////////////////////////////////////////////////////////////////////////////// + + ExecutionPlan (ExecutionPlan* ep) { + _dependencies.push_back(ep); + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor, free dependencies +//////////////////////////////////////////////////////////////////////////////// + + virtual ~ExecutionPlan () { + for (auto i = _dependencies.begin(); i != _dependencies.end(); ++i) { + delete *i; + } + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief return the type of the node +//////////////////////////////////////////////////////////////////////////////// + + virtual NodeType getType () { + return ILLEGAL; + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief add a dependency +//////////////////////////////////////////////////////////////////////////////// + + void addDependency (ExecutionPlan* ep) { + _dependencies.push_back(ep); + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief get all dependencies +//////////////////////////////////////////////////////////////////////////////// + + vector getDependencies () { + return _dependencies; + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief access the pos-th dependency +//////////////////////////////////////////////////////////////////////////////// + + ExecutionPlan* operator[] (size_t pos) { + if (pos > _dependencies.size()) { + return nullptr; + } + else { + return _dependencies.at(pos); + } + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief clone execution plan recursively, this makes the class abstract +//////////////////////////////////////////////////////////////////////////////// + + virtual ExecutionPlan* clone () = 0; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief export to JSON +//////////////////////////////////////////////////////////////////////////////// + + virtual TRI_json_t* toJson (TRI_memory_zone_t* zone); + +// ----------------------------------------------------------------------------- +// --SECTION-- private variables +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief our dependent nodes +//////////////////////////////////////////////////////////////////////////////// + + private: + + std::vector _dependencies; + + }; + + } // namespace triagens::aql +} // namespace triagens + +#endif + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: + + diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index 4ac229bc62..a072378c3b 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -57,6 +57,7 @@ add_executable( Ahuacatl/ahuacatl-statementlist.cpp Ahuacatl/ahuacatl-tokens.cpp Ahuacatl/ahuacatl-variable.cpp + Aql/ExecutionPlan.cpp Aql/Parser.cpp Aql/Query.cpp Aql/QueryError.cpp diff --git a/arangod/Makefile.files b/arangod/Makefile.files index db0b20d3aa..3b716106c8 100644 --- a/arangod/Makefile.files +++ b/arangod/Makefile.files @@ -38,6 +38,7 @@ arangod_libarangod_a_SOURCES = \ arangod/Ahuacatl/ahuacatl-statementlist.cpp \ arangod/Ahuacatl/ahuacatl-tokens.cpp \ arangod/Ahuacatl/ahuacatl-variable.cpp \ + arangod/Aql/ExecutionPlan.cpp \ arangod/Aql/Parser.cpp \ arangod/Aql/Query.cpp \ arangod/Aql/QueryError.cpp \