From a79f72087d201733a89e8369b11e33f44c2ed0e3 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 18 Aug 2014 10:46:47 +0200 Subject: [PATCH 1/2] adding Index caching, and cleaning up last. --- arangod/Aql/ExecutionNode.cpp | 2 +- arangod/Aql/ExecutionNode.h | 8 ++- arangod/Aql/Index.h | 40 ++++------- arangod/Aql/Indexes.h | 127 ++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 30 deletions(-) create mode 100644 arangod/Aql/Indexes.h diff --git a/arangod/Aql/ExecutionNode.cpp b/arangod/Aql/ExecutionNode.cpp index a15f84b9ef..eb90fcd46c 100644 --- a/arangod/Aql/ExecutionNode.cpp +++ b/arangod/Aql/ExecutionNode.cpp @@ -296,7 +296,7 @@ void IndexRangeNode::toJsonHelper (std::map& indexTab, json("database", Json(_vocbase->_name)) ("collection", Json(_collection->name)) ("outVariable", _outVariable->toJson()) - ("index", _index->_index->json(_index->_index)); + ("index", _index->index()->json(_index->index())); // And add it: int len = static_cast(nodes.size()); diff --git a/arangod/Aql/ExecutionNode.h b/arangod/Aql/ExecutionNode.h index 10e68ea139..07e0ffc288 100644 --- a/arangod/Aql/ExecutionNode.h +++ b/arangod/Aql/ExecutionNode.h @@ -658,7 +658,7 @@ namespace triagens { Collection* collection, Variable const* outVariable, Index* index, - vector ranges) + vector* ranges) : ExecutionNode(), _vocbase(vocbase), _collection(collection), @@ -672,6 +672,10 @@ namespace triagens { TRI_ASSERT(_index != nullptr); } + ~IndexRangeNode () { + delete _ranges; + } + //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// @@ -743,7 +747,7 @@ namespace triagens { /// @brief the range info //////////////////////////////////////////////////////////////////////////////// - vector _ranges; + vector* _ranges; }; // ----------------------------------------------------------------------------- diff --git a/arangod/Aql/Index.h b/arangod/Aql/Index.h index d65985e299..aa1239d9a2 100644 --- a/arangod/Aql/Index.h +++ b/arangod/Aql/Index.h @@ -52,15 +52,8 @@ namespace triagens { Index (Index const&) = delete; Index () = delete; - Index (std::string const& name, - struct TRI_vocbase_s* vocbase, - TRI_transaction_type_e accessType, - TRI_index_t* index) - : name(name), - vocbase(vocbase), - collection(nullptr), - accessType(accessType), - _index(index){ + Index (TRI_idx_iid_t id, Collection const* collection) : + _id(id), _collection(collection){ } ~Index() { @@ -71,37 +64,30 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief get the index id +/// @brief get a pointer to the underlying TRI_index_s of the Index //////////////////////////////////////////////////////////////////////////////// - - inline TRI_idx_iid_t id () const { - TRI_ASSERT(_index != nullptr); - return _index->_iid; + + inline TRI_index_s* index () const { + return TRI_LookupIndex(_collection->documentCollection(), _id); } //////////////////////////////////////////////////////////////////////////////// -/// @brief get the index id +/// @brief get the index type //////////////////////////////////////////////////////////////////////////////// - + inline TRI_idx_type_e type () const { - TRI_ASSERT(_index != nullptr); - return _index->_type; + return this->index()->_type; } + +// anything else?? // ----------------------------------------------------------------------------- // --SECTION-- public variables // ----------------------------------------------------------------------------- - std::string const name; - TRI_vocbase_t* vocbase; - TRI_vocbase_col_t* collection; - TRI_transaction_type_e accessType; + TRI_idx_iid_t _id; + Collection const* _collection; -// ----------------------------------------------------------------------------- -// --SECTION-- private variables -// ----------------------------------------------------------------------------- - - TRI_index_t* _index; }; } diff --git a/arangod/Aql/Indexes.h b/arangod/Aql/Indexes.h new file mode 100644 index 0000000000..0ec7a22909 --- /dev/null +++ b/arangod/Aql/Indexes.h @@ -0,0 +1,127 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief Aql, indexes +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2014 ArangoDB GmbH, Cologne, Germany +/// Copyright 2004-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 ArangoDB GmbH, Cologne, Germany +/// +/// @author not James +/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany +/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ARANGODB_AQL_Indexes_H +#define ARANGODB_AQL_Indexes_H 1 + +#include "Basics/Common.h" +#include "Aql/Index.h" + +struct TRI_vocbase_s; + +namespace triagens { + namespace aql { + +// ----------------------------------------------------------------------------- +// --SECTION-- class Indexes +// ----------------------------------------------------------------------------- + + class Indexes { + public: + + Indexes& operator= (Indexes const& other) = delete; + + Indexes (struct TRI_vocbase_s* vocbase) + : _vocbase(vocbase), + _indexes() { + } + + ~Indexes () { + for (auto it = _indexes.begin(); it != _indexes.end(); ++it) { + delete (*it).second; + } + } + + public: + + Index* get (TRI_idx_iid_t id, Collection const* collection) { + auto cid = collection->cid(); + // there may be multiple indexes in the same collection . . . + auto it1 = _cids.begin(); + + do{ + auto it2 = _cids.find(it1, _cids.end(), cid); + if (it2 == _cids.end()) { // couldn't find + return nullptr; + } + }((it2*).second.first == id || it1 == _cids.end()); + + if((it2*).second.first == id){ + return return (it2*).second.second; + } + + return nullptr; + } + + void add (TRI_idx_iid_t id, Collection const* collection) { + // check if index already is in our map + if(this.get(id, collection)!=nullptr){ + auto index = new Index(id, collection); + try { + auto x = std::make_pair(id, index); + _ids.insert(x); + _cids.insert(std::make_pair(collection->cid(), x)); + } + catch (...) { + delete index; + throw; + } + } + } + + std::vector indexIds () const { + std::vector result; + + for (auto x : _indexes) { + result.push_back(x.first); + } + return result; + } + + private: + + struct TRI_vocbase_s* _vocbase; + std::map _ids; + std::map _cids; + }; + + } +} + +#endif + +// ----------------------------------------------------------------------------- +// --SECTION-- END-OF-FILE +// ----------------------------------------------------------------------------- + +// Local Variables: +// mode: outline-minor +// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" +// End: + From f1a7ca51beeff5ad5c211695d0c2984ef0d51e0e Mon Sep 17 00:00:00 2001 From: James Date: Mon, 18 Aug 2014 11:11:27 +0200 Subject: [PATCH 2/2] adding range info to toJsonHelper. --- arangod/Aql/ExecutionNode.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arangod/Aql/ExecutionNode.cpp b/arangod/Aql/ExecutionNode.cpp index eb90fcd46c..8ab0bca9b9 100644 --- a/arangod/Aql/ExecutionNode.cpp +++ b/arangod/Aql/ExecutionNode.cpp @@ -292,11 +292,25 @@ void IndexRangeNode::toJsonHelper (std::map& indexTab, return; } + // put together the range info . . . + Json ranges(Json::List); + + for (auto x : *_ranges) { + Json item(Json::Array); + item("name", Json(x._name)) + ("low", x._low.copy()) + ("lowOpen", Json(x._lowOpen)) + ("high", x._high.copy()) + ("highOpen", Json(x._highOpen)); + ranges(item); + } + // 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())); + ("index", _index->index()->json(_index->index())) + ("ranges", ranges); // And add it: int len = static_cast(nodes.size());