//////////////////////////////////////////////////////////////////////////////// /// @brief Infrastructure for ExecutionPlans /// /// @file arangod/Aql/ExecutionNode.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_NODE_H #define ARANGODB_AQL_EXECUTION_NODE_H 1 #include #include #include #include #include "Aql/Collection.h" #include "Aql/Expression.h" #include "Aql/Index.h" #include "Aql/ModificationOptions.h" #include "Aql/Variable.h" #include "Aql/Types.h" #include "Aql/WalkerWorker.h" using Json = triagens::basics::Json; namespace triagens { namespace aql { class ExecutionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief class ExecutionNode, abstract base class of all execution Nodes //////////////////////////////////////////////////////////////////////////////// class ExecutionNode { //////////////////////////////////////////////////////////////////////////////// /// @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, // done LOOKUP_JOIN, MERGE_JOIN, LOOKUP_INDEX_UNIQUE, LOOKUP_INDEX_RANGE, LOOKUP_FULL_COLLECTION, CONCATENATION, MERGE, REMOTE, INSERT, // done REMOVE, // done REPLACE, // done UPDATE, // done RETURN // done }; // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief default constructor //////////////////////////////////////////////////////////////////////////////// ExecutionNode () : _estimatedCost(0), _varUsageValid(false) { } //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with one dependency //////////////////////////////////////////////////////////////////////////////// ExecutionNode (ExecutionNode* ep) { _dependencies.push_back(ep); } //////////////////////////////////////////////////////////////////////////////// /// @brief destructor, free dependencies; //////////////////////////////////////////////////////////////////////////////// virtual ~ExecutionNode () { } // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief return the type name of the node //////////////////////////////////////////////////////////////////////////////// std::string getTypeString () const; //////////////////////////////////////////////////////////////////////////////// /// @brief add a dependency //////////////////////////////////////////////////////////////////////////////// void addDependency (ExecutionNode* ep) { _dependencies.push_back(ep); } //////////////////////////////////////////////////////////////////////////////// /// @brief get all dependencies //////////////////////////////////////////////////////////////////////////////// std::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 (ExecutionNode* ep) { auto it = _dependencies.begin(); while (it != _dependencies.end()) { if (*it == ep) { _dependencies.erase(it); return true; } ++it; } return false; } //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution Node recursively, this makes the class abstract //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const = 0; // make class abstract //////////////////////////////////////////////////////////////////////////////// /// @brief helper for cloning, use virtual clone methods for dependencies //////////////////////////////////////////////////////////////////////////////// void cloneDependencies (ExecutionNode* theClone) const { auto it = _dependencies.begin(); while (it != _dependencies.end()) { theClone->_dependencies.push_back((*it)->clone()); ++it; } } //////////////////////////////////////////////////////////////////////////////// /// @brief convert to a string, basically for debugging purposes //////////////////////////////////////////////////////////////////////////////// virtual void appendAsString (std::string& st, int indent = 0); //////////////////////////////////////////////////////////////////////////////// /// @brief estimate the cost of the node . . . //////////////////////////////////////////////////////////////////////////////// double getCost () { if (_estimatedCost == 0){ _estimatedCost = estimateCost(); } return _estimatedCost; }; virtual double estimateCost () = 0; //TODO nodes should try harder to estimate their own cost, i.e. the cost //of performing the operation of the node . . . //////////////////////////////////////////////////////////////////////////////// /// @brief walk a complete execution plan recursively //////////////////////////////////////////////////////////////////////////////// void walk (WalkerWorker* worker); //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON, returns an AUTOFREE Json object //////////////////////////////////////////////////////////////////////////////// triagens::basics::Json toJson (TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief toJsonHelper, for a generic node //////////////////////////////////////////////////////////////////////////////// triagens::basics::Json toJsonHelperGeneric ( std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone); //////////////////////////////////////////////////////////////////////////////// /// @brief toJson //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE) = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { return std::vector(); } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { return std::vector(); } //////////////////////////////////////////////////////////////////////////////// /// @brief setVarsUsedLater //////////////////////////////////////////////////////////////////////////////// void setVarsUsedLater (std::unordered_set& v) { _varsUsedLater = v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVarsUsedLater //////////////////////////////////////////////////////////////////////////////// std::unordered_set& getVarsUsedLater () { TRI_ASSERT(_varUsageValid); return _varsUsedLater; } //////////////////////////////////////////////////////////////////////////////// /// @brief setVarsValid //////////////////////////////////////////////////////////////////////////////// void setVarsValid (std::unordered_set& v) { _varsValid = v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVarsValid //////////////////////////////////////////////////////////////////////////////// std::unordered_set& getVarsValid () { TRI_ASSERT(_varUsageValid); return _varsValid; } //////////////////////////////////////////////////////////////////////////////// /// @brief setVarUsageValid //////////////////////////////////////////////////////////////////////////////// void setVarUsageValid () { _varUsageValid = true; } //////////////////////////////////////////////////////////////////////////////// /// @brief invalidateVarUsage //////////////////////////////////////////////////////////////////////////////// void invalidateVarUsage () { _varsUsedLater.clear(); _varsValid.clear(); _varUsageValid = false; } // ----------------------------------------------------------------------------- // --SECTION-- protected variables // ----------------------------------------------------------------------------- protected: //////////////////////////////////////////////////////////////////////////////// /// @brief our dependent nodes //////////////////////////////////////////////////////////////////////////////// std::vector _dependencies; //////////////////////////////////////////////////////////////////////////////// /// @brief NodeType to string mapping //////////////////////////////////////////////////////////////////////////////// static std::unordered_map const TypeNames; //////////////////////////////////////////////////////////////////////////////// /// @brief _estimatedCost = 0 if uninitialised and otherwise stores the result /// of estimateCost() //////////////////////////////////////////////////////////////////////////////// double _estimatedCost; //////////////////////////////////////////////////////////////////////////////// /// @brief _varsUsedLater and _varsValid, the former contains those /// variables that are still needed further down in the chain. The /// latter contains the variables that are set from the dependent nodes /// when an item comes into the current node. Both are only valid if /// _varUsageValid is true. Use ExecutionPlan::findVarUsage to set /// this. //////////////////////////////////////////////////////////////////////////////// std::unordered_set _varsUsedLater; std::unordered_set _varsValid; bool _varUsageValid; }; // ----------------------------------------------------------------------------- // --SECTION-- class SingletonNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SingletonNode //////////////////////////////////////////////////////////////////////////////// class SingletonNode : public ExecutionNode { friend class ExecutionBlock; friend class SingletonBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: SingletonNode () : ExecutionNode() {} //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return SINGLETON; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new SingletonNode(); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a singleton is 1 //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1; } }; // ----------------------------------------------------------------------------- // --SECTION-- class EnumerateCollectionNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class EnumerateCollectionNode //////////////////////////////////////////////////////////////////////////////// class EnumerateCollectionNode : public ExecutionNode { friend class ExecutionBlock; friend class EnumerateCollectionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: EnumerateCollectionNode (TRI_vocbase_t* vocbase, Collection* collection, Variable const* outVariable) : ExecutionNode(), _vocbase(vocbase), _collection(collection), _outVariable(outVariable){ TRI_ASSERT(_vocbase != nullptr); TRI_ASSERT(_collection != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return ENUMERATE_COLLECTION; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new EnumerateCollectionNode(_vocbase, _collection, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of an enumerate collection node is a multiple of the cost of /// its unique dependency //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return static_cast(_collection->count()) * _dependencies.at(0)->getCost(); //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; v.push_back(_outVariable); return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief the database //////////////////////////////////////////////////////////////////////////////// TRI_vocbase_t* _vocbase; //////////////////////////////////////////////////////////////////////////////// /// @brief collection //////////////////////////////////////////////////////////////////////////////// Collection* _collection; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class EnumerateListNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class EnumerateListNode //////////////////////////////////////////////////////////////////////////////// class EnumerateListNode : public ExecutionNode { friend class ExecutionBlock; friend class EnumerateListBlock; friend struct VarUsageFinder; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: EnumerateListNode (Variable const* inVariable, Variable const* outVariable) : ExecutionNode(), _inVariable(inVariable), _outVariable(outVariable) { TRI_ASSERT(_inVariable != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return ENUMERATE_LIST; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new EnumerateListNode(_inVariable, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of an enumerate list node is . . . FIXME //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1000 * _dependencies.at(0)->getCost(); //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; v.push_back(_outVariable); return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable to read from //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class IndexRangeNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief struct to keep an upper or lower bound for the range info. Use /// nullptr instead if you want to have no bound. //////////////////////////////////////////////////////////////////////////////// struct RangeInfoBound{ RangeInfoBound(AstNode const* bound, bool include) : _include(include) { _bound = Json(TRI_UNKNOWN_MEM_ZONE, bound->toJson(TRI_UNKNOWN_MEM_ZONE)); } RangeInfoBound(Json bound, bool include) : _bound(bound), _include(include) { } ~RangeInfoBound(){} RangeInfoBound ( const RangeInfoBound& copy ) { _bound = Json(TRI_UNKNOWN_MEM_ZONE, TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, copy._bound.json())); _include = copy._include; } Json toJson () const { Json item(basics::Json::Array); item("bound", Json(TRI_UNKNOWN_MEM_ZONE, TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, _bound.json()))) ("include", Json(_include)); return item; } Json _bound; bool _include; }; //////////////////////////////////////////////////////////////////////////////// /// @brief struct to keep range info //////////////////////////////////////////////////////////////////////////////// struct RangeInfo{ RangeInfo ( std::string name, RangeInfoBound const* low, RangeInfoBound const* high ) : _name(name), _low(low), _high(high) {} ~RangeInfo(){ if(_low != nullptr){ delete _low; } if(_high != nullptr){ delete _high; } } Json toJson () { Json item(basics::Json::Array); item("name", Json(_name)) ("low", _low->toJson()) ("high", _high->toJson()); return item; } std::string toString() { return this->toJson().toString(); } std::string _name; RangeInfoBound const* _low; RangeInfoBound const* _high; }; //////////////////////////////////////////////////////////////////////////////// /// @brief class IndexRangeNode //////////////////////////////////////////////////////////////////////////////// class IndexRangeNode: public ExecutionNode { friend class ExecutionBlock; friend class IndexRangeBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: IndexRangeNode (TRI_vocbase_t* vocbase, Collection* collection, Variable const* outVariable, Index* index, vector* ranges) : ExecutionNode(), _vocbase(vocbase), _collection(collection), _outVariable(outVariable), _index(index), _ranges(ranges) { TRI_ASSERT(_vocbase != nullptr); TRI_ASSERT(_collection != nullptr); TRI_ASSERT(_outVariable != nullptr); TRI_ASSERT(_index != nullptr); } ~IndexRangeNode () { delete _ranges; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return INDEX_RANGE; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new IndexRangeNode(_vocbase, _collection, _outVariable, _index, _ranges); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of an enumerate collection node is a multiple of the cost of /// its unique dependency //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1; //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; v.push_back(_outVariable); return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief the database //////////////////////////////////////////////////////////////////////////////// TRI_vocbase_t* _vocbase; //////////////////////////////////////////////////////////////////////////////// /// @brief collection //////////////////////////////////////////////////////////////////////////////// Collection* _collection; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief the index //////////////////////////////////////////////////////////////////////////////// Index* _index; //////////////////////////////////////////////////////////////////////////////// /// @brief the range info //////////////////////////////////////////////////////////////////////////////// vector* _ranges; }; // ----------------------------------------------------------------------------- // --SECTION-- class LimitNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class LimitNode //////////////////////////////////////////////////////////////////////////////// class LimitNode : public ExecutionNode { friend class ExecutionBlock; friend class LimitBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: LimitNode (size_t o, size_t l) : ExecutionNode(), _offset(o), _limit(l) { } LimitNode (size_t l) : ExecutionNode(), _offset(0), _limit(l) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return LIMIT; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new LimitNode(_offset, _limit); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a limit node is the minimum of the _limit, and the cost /// the dependency . . . //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1.005 * std::min(static_cast(_limit), _dependencies.at(0)->getCost()); //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: size_t _offset; size_t _limit; }; // ----------------------------------------------------------------------------- // --SECTION-- class CalculationNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class CalculationNode //////////////////////////////////////////////////////////////////////////////// class CalculationNode : public ExecutionNode { friend class ExecutionBlock; friend class CalculationBlock; public: //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// CalculationNode (Expression* expr, Variable const* outVariable) : ExecutionNode(), _expression(expr), _outVariable(outVariable) { TRI_ASSERT(_expression != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief destructor //////////////////////////////////////////////////////////////////////////////// ~CalculationNode () { if (_expression != nullptr) { delete _expression; } } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return CALCULATION; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new CalculationNode(_expression->clone(), _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief return out variable //////////////////////////////////////////////////////////////////////////////// Variable const* outVariable () const { return _outVariable; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the expression //////////////////////////////////////////////////////////////////////////////// Expression* expression () const { return _expression; } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a calculation node is the cost of the unique dependency // times a constant //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 2 * _dependencies.at(0)->getCost(); //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::unordered_set vars = _expression->variables(); std::vector v; for (auto vv : vars) { v.push_back(vv); } return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; v.push_back(_outVariable); return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to have an expression and where to write the result //////////////////////////////////////////////////////////////////////////////// Expression* _expression; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class SubqueryNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SubqueryNode //////////////////////////////////////////////////////////////////////////////// class SubqueryNode : public ExecutionNode { friend class ExecutionBlock; friend class SubqueryBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: SubqueryNode (ExecutionNode* subquery, Variable const* outVariable) : ExecutionNode(), _subquery(subquery), _outVariable(outVariable) { TRI_ASSERT(_subquery != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return SUBQUERY; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new SubqueryNode(_subquery->clone(), _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief getter for subquery //////////////////////////////////////////////////////////////////////////////// ExecutionNode* getSubquery () { return _subquery; } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a subquery node is the cost of its unique dependency /// times a small constant //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1.005 * _dependencies.at(0)->getCost(); //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; v.push_back(_outVariable); return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to have an expression and where to write the result //////////////////////////////////////////////////////////////////////////////// ExecutionNode* _subquery; //////////////////////////////////////////////////////////////////////////////// /// @brief variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class FilterNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class FilterNode //////////////////////////////////////////////////////////////////////////////// class FilterNode : public ExecutionNode { friend class ExecutionBlock; friend class FilterBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: FilterNode (Variable const* inVariable) : ExecutionNode(), _inVariable(inVariable) { TRI_ASSERT(_inVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return FILTER; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new FilterNode(_inVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a filter node is . . . FIXME //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return _dependencies.at(0)->getCost() * 0.105; //FIXME! 0.005 is the cost of doing the filter node under the //assumption that it returns 10% of the results of its dependency } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable to read from //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class SortNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SortNode //////////////////////////////////////////////////////////////////////////////// class SortNode : public ExecutionNode { friend class ExecutionBlock; friend class SortBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: SortNode (std::vector> elements) : ExecutionNode(), _elements(elements) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return SORT; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new SortNode(_elements); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a sort node is . . . FIXME //////////////////////////////////////////////////////////////////////////////// double estimateCost () { double depCost = _dependencies.at(0)->getCost(); return log(depCost) * depCost; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; for (auto p : _elements) { v.push_back(p.first); } return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief pairs, consisting of variable and sort direction /// (true = ascending | false = descending) //////////////////////////////////////////////////////////////////////////////// std::vector> _elements; }; // ----------------------------------------------------------------------------- // --SECTION-- class AggregateNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class AggregateNode //////////////////////////////////////////////////////////////////////////////// class AggregateNode : public ExecutionNode { friend class ExecutionBlock; friend class AggregateBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: AggregateNode (std::vector> aggregateVariables, Variable const* outVariable, std::unordered_map const& variableMap) : ExecutionNode(), _aggregateVariables(aggregateVariables), _outVariable(outVariable), _variableMap(variableMap) { // outVariable can be a nullptr } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return AGGREGATE; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new AggregateNode(_aggregateVariables, _outVariable, _variableMap); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of an aggregate node is . . . FIXME //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 2 * _dependencies.at(0)->getCost(); //FIXME improve this estimate . . . } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; for (auto p : _aggregateVariables) { v.push_back(p.second); } return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; for (auto p : _aggregateVariables) { v.push_back(p.first); } if (_outVariable != nullptr) { v.push_back(_outVariable); } return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief input/output variables for the aggregation (out, in) //////////////////////////////////////////////////////////////////////////////// std::vector> _aggregateVariables; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to (might be null) //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief map of all variable ids and names (needed to construct group data) //////////////////////////////////////////////////////////////////////////////// std::unordered_map const _variableMap; }; // ----------------------------------------------------------------------------- // --SECTION-- class ReturnNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class ReturnNode //////////////////////////////////////////////////////////////////////////////// class ReturnNode : public ExecutionNode { friend class ExecutionBlock; friend class ReturnBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: ReturnNode (Variable const* inVariable) : ExecutionNode(), _inVariable(inVariable) { TRI_ASSERT(_inVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return RETURN; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new ReturnNode(_inVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a return node is the cost of its only dependency . . . //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return _dependencies.at(0)->getCost(); } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class ModificationNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief abstract base class for modification operations //////////////////////////////////////////////////////////////////////////////// class ModificationNode : public ExecutionNode { friend class ExecutionBlock; friend class ModificationBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection and options //////////////////////////////////////////////////////////////////////////////// protected: ModificationNode (TRI_vocbase_t* vocbase, Collection* collection, ModificationOptions const& options) : ExecutionNode(), _vocbase(vocbase), _collection(collection), _options(options) { TRI_ASSERT(_vocbase != nullptr); TRI_ASSERT(_collection != nullptr); } // ----------------------------------------------------------------------------- // --SECTION-- protected variables // ----------------------------------------------------------------------------- protected: //////////////////////////////////////////////////////////////////////////////// /// @brief _vocbase, the database //////////////////////////////////////////////////////////////////////////////// TRI_vocbase_t* _vocbase; //////////////////////////////////////////////////////////////////////////////// /// @brief collection //////////////////////////////////////////////////////////////////////////////// Collection* _collection; //////////////////////////////////////////////////////////////////////////////// /// @brief modification operation options //////////////////////////////////////////////////////////////////////////////// ModificationOptions _options; }; // ----------------------------------------------------------------------------- // --SECTION-- class RemoveNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class RemoveNode //////////////////////////////////////////////////////////////////////////////// class RemoveNode : public ModificationNode { friend class ExecutionBlock; friend class RemoveBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: RemoveNode (TRI_vocbase_t* vocbase, Collection* collection, ModificationOptions const& options, Variable const* inVariable, Variable const* outVariable) : ModificationNode(vocbase, collection, options), _inVariable(inVariable), _outVariable(outVariable) { TRI_ASSERT(_inVariable != nullptr); // _outVariable might be a nullptr } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return REMOVE; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new RemoveNode(_vocbase, _collection, _options, _inVariable, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a remove node is a multiple of the cost of its unique /// dependency //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return _dependencies.at(0)->getCost(); // TODO: improve this estimate! } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; if (_outVariable != nullptr) { v.push_back(_outVariable); } return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable (might be a nullptr) //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class InsertNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class InsertNode //////////////////////////////////////////////////////////////////////////////// class InsertNode : public ModificationNode { friend class ExecutionBlock; friend class InsertBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: InsertNode (TRI_vocbase_t* vocbase, Collection* collection, ModificationOptions const& options, Variable const* inVariable, Variable const* outVariable) : ModificationNode(vocbase, collection, options), _inVariable(inVariable), _outVariable(outVariable) { TRI_ASSERT(_inVariable != nullptr); // _outVariable might be a nullptr } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return INSERT; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new InsertNode(_vocbase, _collection, _options, _inVariable, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a remove node is a multiple of the cost of its unique /// dependency //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1000 * _dependencies.at(0)->getCost(); //FIXME change this! } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; if (_outVariable != nullptr) { v.push_back(_outVariable); } return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class UpdateNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class UpdateNode //////////////////////////////////////////////////////////////////////////////// class UpdateNode : public ModificationNode { friend class ExecutionBlock; friend class UpdateBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: UpdateNode (TRI_vocbase_t* vocbase, Collection* collection, ModificationOptions const& options, Variable const* inVariable, Variable const* outVariable) : ModificationNode(vocbase, collection, options), _inVariable(inVariable), _outVariable(outVariable) { TRI_ASSERT(_inVariable != nullptr); // _outVariable might be a nullptr } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return UPDATE; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new UpdateNode(_vocbase, _collection, _options, _inVariable, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a remove node is a multiple of the cost of its unique /// dependency //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1000 * _dependencies.at(0)->getCost(); //FIXME change this! } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; if (_outVariable != nullptr) { v.push_back(_outVariable); } return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class ReplaceNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class ReplaceNode //////////////////////////////////////////////////////////////////////////////// class ReplaceNode : public ModificationNode { friend class ExecutionBlock; friend class ReplaceBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: ReplaceNode (TRI_vocbase_t* vocbase, Collection* collection, ModificationOptions const& options, Variable const* inVariable, Variable const* outVariable) : ModificationNode(vocbase, collection, options), _inVariable(inVariable), _outVariable(outVariable) { TRI_ASSERT(_inVariable != nullptr); // _outVariable might be a nullptr } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// NodeType getType () const override { return REPLACE; } //////////////////////////////////////////////////////////////////////////////// /// @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 ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new ReplaceNode(_vocbase, _collection, _options, _inVariable, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief the cost of a remove node is a multiple of the cost of its unique /// dependency //////////////////////////////////////////////////////////////////////////////// double estimateCost () { return 1000 * _dependencies.at(0)->getCost(); //FIXME change this! } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesUsedHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesUsedHere () { std::vector v; v.push_back(_inVariable); return v; } //////////////////////////////////////////////////////////////////////////////// /// @brief getVariablesSetHere //////////////////////////////////////////////////////////////////////////////// virtual std::vector getVariablesSetHere () { std::vector v; if (_outVariable != nullptr) { v.push_back(_outVariable); } return v; } // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; } // namespace triagens::aql } // namespace triagens #endif // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" // End: