1
0
Fork 0

initial version of IndexRangeNode.

This commit is contained in:
James 2014-08-15 13:52:52 +02:00
parent a0db57b7f9
commit 47244fb48e
3 changed files with 148 additions and 116 deletions

View File

@ -44,6 +44,7 @@ std::unordered_map<int, std::string const> const ExecutionNode::TypeNames{
{ static_cast<int>(SINGLETON), "SingletonNode" },
{ static_cast<int>(ENUMERATE_COLLECTION), "EnumerateCollectionNode" },
{ static_cast<int>(ENUMERATE_LIST), "EnumerateListNode" },
{ static_cast<int>(INDEX_RANGE), "IndexRangeNode" },
{ static_cast<int>(LIMIT), "LimitNode" },
{ static_cast<int>(CALCULATION), "CalculationNode" },
{ static_cast<int>(SUBQUERY), "SubqueryNode" },
@ -264,6 +265,33 @@ void EnumerateListNode::toJsonHelper (std::map<ExecutionNode*, int>& indexTab,
indexTab.insert(make_pair(this, len));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief toJson, for IndexRangeNode
////////////////////////////////////////////////////////////////////////////////
void IndexRangeNode::toJsonHelper (std::map<ExecutionNode*, int>& indexTab,
triagens::basics::Json& nodes,
TRI_memory_zone_t* zone) {
Json json(ExecutionNode::toJsonHelperGeneric(indexTab, nodes, zone));
// call base class method
if (json.isEmpty()) {
return;
}
// Now put info about vocbase and cid in there
json("database", Json(_vocbase->_name))
("collection", Json(_collection->name))
("outVariable", _outVariable->toJson())
("index", _index->_index->json(_index->_index));
// And add it:
int len = static_cast<int>(nodes.size());
nodes(json);
indexTab.insert(make_pair(this, len));
}
// -----------------------------------------------------------------------------
// --SECTION-- methods of LimitNode
// -----------------------------------------------------------------------------

View File

@ -416,109 +416,7 @@ namespace triagens {
};
// -----------------------------------------------------------------------------
// --SECTION-- class
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @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)
: ExecutionNode(),
_vocbase(vocbase),
_collection(collection),
_outVariable(outVariable),
_index(index)
{
TRI_ASSERT(_vocbase != nullptr);
TRI_ASSERT(_collection != nullptr);
TRI_ASSERT(_outVariable != nullptr);
TRI_ASSERT(_index != nullptr);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the type of the node
////////////////////////////////////////////////////////////////////////////////
NodeType getType () const override {
return INDEX_RANGE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief export to JSON
////////////////////////////////////////////////////////////////////////////////
//TODO: this is just a place holder
virtual void toJsonHelper (std::map<ExecutionNode*, int>& 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);
cloneDependencies(c);
return static_cast<ExecutionNode*>(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 . . .
}
// -----------------------------------------------------------------------------
// --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;
};
// -----------------------------------------------------------------------------
// --SECTION-- class EnumerateListNode
// -----------------------------------------------------------------------------
@ -601,6 +499,108 @@ namespace triagens {
};
// -----------------------------------------------------------------------------
// --SECTION-- class IndexRangeNode
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @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)
: ExecutionNode(),
_vocbase(vocbase),
_collection(collection),
_outVariable(outVariable),
_index(index)
{
TRI_ASSERT(_vocbase != nullptr);
TRI_ASSERT(_collection != nullptr);
TRI_ASSERT(_outVariable != nullptr);
TRI_ASSERT(_index != nullptr);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the type of the node
////////////////////////////////////////////////////////////////////////////////
NodeType getType () const override {
return INDEX_RANGE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief export to JSON
////////////////////////////////////////////////////////////////////////////////
virtual void toJsonHelper (std::map<ExecutionNode*, int>& 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);
cloneDependencies(c);
return static_cast<ExecutionNode*>(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 . . .
}
// -----------------------------------------------------------------------------
// --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;
};
// -----------------------------------------------------------------------------
// --SECTION-- class LimitNode

View File

@ -54,11 +54,13 @@ namespace triagens {
Index (std::string const& name,
struct TRI_vocbase_s* vocbase,
TRI_transaction_type_e accessType)
TRI_transaction_type_e accessType,
TRI_index_t* index)
: name(name),
vocbase(vocbase),
collection(nullptr),
accessType(accessType) {
accessType(accessType),
_index(index){
}
~Index() {
@ -69,23 +71,21 @@ namespace triagens {
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief get the collection id
/// @brief get the index id
////////////////////////////////////////////////////////////////////////////////
inline TRI_voc_cid_t cid () const {
TRI_ASSERT(collection != nullptr);
return collection->_cid;
inline TRI_idx_iid_t id () const {
TRI_ASSERT(_index != nullptr);
return _index->_iid;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get the pointer to the document collection
/// @brief get the index id
////////////////////////////////////////////////////////////////////////////////
inline TRI_document_collection_t* documentCollection () const {
TRI_ASSERT(collection != nullptr);
TRI_ASSERT(collection->_collection != nullptr);
return collection->_collection;
inline TRI_idx_type_e type () const {
TRI_ASSERT(_index != nullptr);
return _index->_type;
}
// -----------------------------------------------------------------------------
@ -95,9 +95,13 @@ namespace triagens {
std::string const name;
TRI_vocbase_t* vocbase;
TRI_vocbase_col_t* collection;
TRI_idx_iid_t id;
TRI_idx_type_e type;
TRI_transaction_type_e accessType;
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
TRI_index_t* _index;
};
}