1
0
Fork 0

adding Index caching, and cleaning up last.

This commit is contained in:
James 2014-08-18 10:46:47 +02:00
parent ac58a0a9d3
commit a79f72087d
4 changed files with 147 additions and 30 deletions

View File

@ -296,7 +296,7 @@ void IndexRangeNode::toJsonHelper (std::map<ExecutionNode*, int>& 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<int>(nodes.size());

View File

@ -658,7 +658,7 @@ namespace triagens {
Collection* collection,
Variable const* outVariable,
Index* index,
vector<RangeInfo> ranges)
vector<RangeInfo>* 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<RangeInfo> _ranges;
vector<RangeInfo>* _ranges;
};
// -----------------------------------------------------------------------------

View File

@ -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;
};
}

127
arangod/Aql/Indexes.h Normal file
View File

@ -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 <cid>
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<std::string> indexIds () const {
std::vector<std::string> result;
for (auto x : _indexes) {
result.push_back(x.first);
}
return result;
}
private:
struct TRI_vocbase_s* _vocbase;
std::map<TRI_idx_iid_t, Index*> _ids;
std::map<TRI_voc_cid_t, _indexes> _cids;
};
}
}
#endif
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End: