//////////////////////////////////////////////////////////////////////////////// /// @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 #include #include #include "Aql/Variable.h" #include "Aql/Types.h" namespace triagens { namespace aql { class ExecutionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief class ExecutionPlan, abstract base class of all execution plans //////////////////////////////////////////////////////////////////////////////// class ExecutionPlan { //////////////////////////////////////////////////////////////////////////////// /// @brief node type //////////////////////////////////////////////////////////////////////////////// public: enum NodeType { ILLEGAL, SINGLETON, // done ENUMERATE_COLLECTION, // done INDEX_RANGE, ENUMERATE_LIST, // done FILTER, // done LIMIT, // done INTERSECTION, PROJECTION, // done CALCULATION, // done SUBQUERY, // done SORT, // done AGGREGATE_ON_SORTED, AGGREGATE_ON_UNSORTED, // todo LOOKUP_JOIN, MERGE_JOIN, LOOKUP_INDEX_UNIQUE, LOOKUP_INDEX_RANGE, LOOKUP_FULL_COLLECTION, CONCATENATION, MERGE, REMOTE, INSERT, REMOVE, REPLACE, UPDATE, ROOT // done }; // ----------------------------------------------------------------------------- // --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 () const { return ILLEGAL; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("ExecutionPlan (abstract)"); } //////////////////////////////////////////////////////////////////////////////// /// @brief add a dependency //////////////////////////////////////////////////////////////////////////////// void addDependency (ExecutionPlan* ep) { _dependencies.push_back(ep); } //////////////////////////////////////////////////////////////////////////////// /// @brief get all dependencies //////////////////////////////////////////////////////////////////////////////// vector getDependencies () const { return _dependencies; } //////////////////////////////////////////////////////////////////////////////// /// @brief remove a dependency, returns true if the pointer was found and /// removed, please note that this does not delete ep! //////////////////////////////////////////////////////////////////////////////// bool removeDependency (ExecutionPlan* ep) { auto it = _dependencies.begin(); while (it != _dependencies.end()) { if (*it == ep) { _dependencies.erase(it); return true; } ++it; } return false; } //////////////////////////////////////////////////////////////////////////////// /// @brief access the pos-th dependency //////////////////////////////////////////////////////////////////////////////// ExecutionPlan* operator[] (size_t pos) const { if (pos > _dependencies.size()) { return nullptr; } else { return _dependencies.at(pos); } } //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively, this makes the class abstract //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const = 0; // make class abstract //////////////////////////////////////////////////////////////////////////////// /// @brief helper for cloning, use virtual clone methods for dependencies //////////////////////////////////////////////////////////////////////////////// void cloneDependencies (ExecutionPlan* theClone) const { auto it = _dependencies.begin(); while (it != _dependencies.end()) { theClone->_dependencies.push_back((*it)->clone()); ++it; } } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON, returns an AUTOFREE Json object //////////////////////////////////////////////////////////////////////////////// triagens::basics::Json toJson ( TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief helpers for export to JSON, appends an entry to nodes, indexMap is the /// map from nodes to indices in list //////////////////////////////////////////////////////////////////////////////// protected: triagens::basics::Json toJsonHelperGeneric ( std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone); virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE) = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief convert to a string, basically for debugging purposes //////////////////////////////////////////////////////////////////////////////// public: virtual void appendAsString (std::string& st, int indent = 0); //////////////////////////////////////////////////////////////////////////////// /// @brief functionality to walk an execution plan recursively //////////////////////////////////////////////////////////////////////////////// class WalkerWorker { public: WalkerWorker () {}; virtual ~WalkerWorker () {}; virtual void before (ExecutionPlan* eb) {}; virtual void after (ExecutionPlan* eb) {}; virtual void enterSubquery (ExecutionPlan* super, ExecutionPlan* sub) {}; virtual void leaveSubquery (ExecutionPlan* super, ExecutionPlan* sub) {}; }; void walk (WalkerWorker& worker); // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief our dependent nodes //////////////////////////////////////////////////////////////////////////////// protected: std::vector _dependencies; }; // ----------------------------------------------------------------------------- // --SECTION-- class SingletonPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SingletonPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class SingletonPlan : public ExecutionPlan { friend class ExecutionBlock; friend class SingletonBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: SingletonPlan () : ExecutionPlan() { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SINGLETON; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("SingletonPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new SingletonPlan(); cloneDependencies(c); return static_cast(c); } }; // ----------------------------------------------------------------------------- // --SECTION-- class EnumerateCollectionPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class EnumerateCollectionPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class EnumerateCollectionPlan : public ExecutionPlan { friend class ExecutionBlock; friend class EnumerateCollectionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: EnumerateCollectionPlan (TRI_vocbase_t* vocbase, std::string collname, VariableId outVarNumber, std::string outVarName) : ExecutionPlan(), _vocbase(vocbase), _collname(collname), _outVarNumber(outVarNumber), _outVarName(outVarName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return ENUMERATE_COLLECTION; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("EnumerateCollectionPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new EnumerateCollectionPlan(_vocbase, _collname, _outVarNumber, _outVarName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief _vocbase, the database //////////////////////////////////////////////////////////////////////////////// TRI_vocbase_t* _vocbase; //////////////////////////////////////////////////////////////////////////////// /// @brief _collname, the collection name //////////////////////////////////////////////////////////////////////////////// std::string _collname; //////////////////////////////////////////////////////////////////////////////// /// @brief _outVarNumber, output variable //////////////////////////////////////////////////////////////////////////////// VariableId _outVarNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _outVarName, name of variable to write to //////////////////////////////////////////////////////////////////////////////// std::string _outVarName; }; // ----------------------------------------------------------------------------- // --SECTION-- class EnumerateListPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class EnumerateListPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class EnumerateListPlan : public ExecutionPlan { friend class ExecutionBlock; friend class EnumerateListBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: EnumerateListPlan (VariableId varNumber, std::string varName, VariableId outVarNumber, std::string outVarName) : ExecutionPlan(), _varNumber(varNumber), _varName(varName), _outVarNumber(outVarNumber), _outVarName(outVarName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return ENUMERATE_LIST; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("EnumerateListPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new EnumerateListPlan(_varNumber, _varName, _outVarNumber, _outVarName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief _varNumber, input variable //////////////////////////////////////////////////////////////////////////////// VariableId _varNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _varName, name of variable to read from //////////////////////////////////////////////////////////////////////////////// std::string _varName; //////////////////////////////////////////////////////////////////////////////// /// @brief _outVarNumber, output variable //////////////////////////////////////////////////////////////////////////////// VariableId _outVarNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _outVarName, name of variable to write to //////////////////////////////////////////////////////////////////////////////// std::string _outVarName; }; // ----------------------------------------------------------------------------- // --SECTION-- class LimitPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class LimitPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class LimitPlan : public ExecutionPlan { friend class ExecutionBlock; friend class LimitBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: LimitPlan (size_t o, size_t l) : ExecutionPlan(), _offset(o), _limit(l) { } LimitPlan (size_t l) : ExecutionPlan(), _offset(0), _limit(l) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return LIMIT; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("LimitPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new LimitPlan(_offset, _limit); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: size_t _offset; size_t _limit; }; // ----------------------------------------------------------------------------- // --SECTION-- class ProjectionPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class ProjectionPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class ProjectionPlan : public ExecutionPlan { friend class ExecutionBlock; friend class ProjectionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: ProjectionPlan (VariableId inVar, std::string inVarName, VariableId outVar, std::string outVarName, std::vector keepAttributes) : ExecutionPlan(), _inVar(inVar), _inVarName(inVarName), _outVar(outVar), _outVarName(outVarName), _keepAttributes(keepAttributes) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return PROJECTION; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("ProjectionPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new ProjectionPlan(_inVar, _inVarName, _outVar, _outVarName, _keepAttributes); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable //////////////////////////////////////////////////////////////////////////////// VariableId _inVar; //////////////////////////////////////////////////////////////////////////////// /// @brief _inVarName, name of variable to read from //////////////////////////////////////////////////////////////////////////////// std::string _inVarName; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// VariableId _outVar; //////////////////////////////////////////////////////////////////////////////// /// @brief _outVarName, name of variable to write to //////////////////////////////////////////////////////////////////////////////// std::string _outVarName; //////////////////////////////////////////////////////////////////////////////// /// @brief vector of attributes to leave in the object //////////////////////////////////////////////////////////////////////////////// std::vector _keepAttributes; }; // ----------------------------------------------------------------------------- // --SECTION-- class CalculationPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class CalculationPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class CalculationPlan : public ExecutionPlan { friend class ExecutionBlock; friend class CalculationBlock; public: //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// CalculationPlan (AqlExpression* expr, VariableId varNumber, std::string varName) : ExecutionPlan(), _expression(expr), _varNumber(varNumber), _varName(varName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief destructor //////////////////////////////////////////////////////////////////////////////// ~CalculationPlan () { if (_expression != nullptr) { delete _expression; } } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return CALCULATION; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("CalculationPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new CalculationPlan(_expression->clone(), _varNumber, _varName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to have an expression and where to write the result //////////////////////////////////////////////////////////////////////////////// AqlExpression* _expression; //////////////////////////////////////////////////////////////////////////////// /// @brief _varNumber, global number of variable to write to //////////////////////////////////////////////////////////////////////////////// VariableId _varNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _varName, name of variable to write to //////////////////////////////////////////////////////////////////////////////// std::string _varName; }; // ----------------------------------------------------------------------------- // --SECTION-- class SubqueryPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SubqueryPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class SubqueryPlan : public ExecutionPlan { friend class ExecutionBlock; friend class SubqueryBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: SubqueryPlan (ExecutionPlan* subquery, VariableId varNumber, std::string varName) : ExecutionPlan(), _subquery(subquery), _varNumber(varNumber), _varName(varName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SUBQUERY; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("SubqueryPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new SubqueryPlan(_subquery->clone(), _varNumber, _varName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief getter for subquery //////////////////////////////////////////////////////////////////////////////// ExecutionPlan* getSubquery () { return _subquery; } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to have an expression and where to write the result //////////////////////////////////////////////////////////////////////////////// ExecutionPlan* _subquery; //////////////////////////////////////////////////////////////////////////////// /// @brief _varNumber, global number of variable to write to //////////////////////////////////////////////////////////////////////////////// VariableId _varNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _varName, name of variable to write to //////////////////////////////////////////////////////////////////////////////// std::string _varName; }; // ----------------------------------------------------------------------------- // --SECTION-- class FilterPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class FilterPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class FilterPlan : public ExecutionPlan { friend class ExecutionBlock; friend class FilterBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: FilterPlan (VariableId varNumber, std::string varName) : ExecutionPlan(), _varNumber(varNumber), _varName(varName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return FILTER; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("FilterPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new FilterPlan(_varNumber, _varName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief _varNumber, input variable //////////////////////////////////////////////////////////////////////////////// VariableId _varNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _varName, name of variable to read from //////////////////////////////////////////////////////////////////////////////// std::string _varName; }; // ----------------------------------------------------------------------------- // --SECTION-- class SortPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SortPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class SortPlan : public ExecutionPlan { friend class ExecutionBlock; friend class SortBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: SortPlan (std::vector varNumbers, std::vector varNames, std::vector sortAscending) : ExecutionPlan(), _varNumbers(varNumbers), _varNames(varNames), _sortAscending(sortAscending) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SORT; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("SortPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new SortPlan(_varNumbers, _varNames, _sortAscending); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief _varNumbers, input variables for sorting //////////////////////////////////////////////////////////////////////////////// std::vector _varNumbers; //////////////////////////////////////////////////////////////////////////////// /// @brief _varNames, name of variables for sorting //////////////////////////////////////////////////////////////////////////////// std::vector _varNames; //////////////////////////////////////////////////////////////////////////////// /// @brief vector of attributes to sort by //////////////////////////////////////////////////////////////////////////////// std::vector _sortAscending; }; // ----------------------------------------------------------------------------- // --SECTION-- class AggregateOnUnsortedPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class AggregateOnUnsortedPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class AggregateOnUnsortedPlan : public ExecutionPlan { friend class ExecutionBlock; friend class AggregateOnUnsortedBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: AggregateOnUnsortedPlan (std::vector varNumbers, std::vector varNames, VariableId outVarNumber, std::string outVarName) : ExecutionPlan(), _varNumbers(varNumbers), _varNames(varNames), _outVarNumber(outVarNumber), _outVarName(outVarName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SORT; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("AggregateOnUnsortedPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new AggregateOnUnsortedPlan(_varNumbers, _varNames, _outVarNumber, _outVarName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief _varNumbers, input variables for the aggregation //////////////////////////////////////////////////////////////////////////////// std::vector _varNumbers; //////////////////////////////////////////////////////////////////////////////// /// @brief _varNames, name of variables for the aggregation //////////////////////////////////////////////////////////////////////////////// std::vector _varNames; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// VariableId _outVarNumber; //////////////////////////////////////////////////////////////////////////////// /// @brief _outVarName, name of variable to write to //////////////////////////////////////////////////////////////////////////////// std::string _outVarName; }; // ----------------------------------------------------------------------------- // --SECTION-- class RootPlan // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class RootPlan, derived from ExecutionPlan //////////////////////////////////////////////////////////////////////////////// class RootPlan : public ExecutionPlan { friend class ExecutionBlock; friend class RootBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: RootPlan (VariableId varNumber, std::string varName) : ExecutionPlan(), _varNumber(varNumber), _varName(varName) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return ROOT; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("RootPlan"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution plan recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionPlan* clone () const { auto c = new RootPlan(_varNumber, _varName); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: VariableId _varNumber; std::string _varName; }; } // namespace triagens::aql } // namespace triagens #endif // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" // End: