mirror of https://gitee.com/bigwinds/arangodb
adding Index caching, and cleaning up last.
This commit is contained in:
parent
ac58a0a9d3
commit
a79f72087d
|
@ -296,7 +296,7 @@ void IndexRangeNode::toJsonHelper (std::map<ExecutionNode*, int>& indexTab,
|
||||||
json("database", Json(_vocbase->_name))
|
json("database", Json(_vocbase->_name))
|
||||||
("collection", Json(_collection->name))
|
("collection", Json(_collection->name))
|
||||||
("outVariable", _outVariable->toJson())
|
("outVariable", _outVariable->toJson())
|
||||||
("index", _index->_index->json(_index->_index));
|
("index", _index->index()->json(_index->index()));
|
||||||
|
|
||||||
// And add it:
|
// And add it:
|
||||||
int len = static_cast<int>(nodes.size());
|
int len = static_cast<int>(nodes.size());
|
||||||
|
|
|
@ -658,7 +658,7 @@ namespace triagens {
|
||||||
Collection* collection,
|
Collection* collection,
|
||||||
Variable const* outVariable,
|
Variable const* outVariable,
|
||||||
Index* index,
|
Index* index,
|
||||||
vector<RangeInfo> ranges)
|
vector<RangeInfo>* ranges)
|
||||||
: ExecutionNode(),
|
: ExecutionNode(),
|
||||||
_vocbase(vocbase),
|
_vocbase(vocbase),
|
||||||
_collection(collection),
|
_collection(collection),
|
||||||
|
@ -672,6 +672,10 @@ namespace triagens {
|
||||||
TRI_ASSERT(_index != nullptr);
|
TRI_ASSERT(_index != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~IndexRangeNode () {
|
||||||
|
delete _ranges;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief return the type of the node
|
/// @brief return the type of the node
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -743,7 +747,7 @@ namespace triagens {
|
||||||
/// @brief the range info
|
/// @brief the range info
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
vector<RangeInfo> _ranges;
|
vector<RangeInfo>* _ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -52,15 +52,8 @@ namespace triagens {
|
||||||
Index (Index const&) = delete;
|
Index (Index const&) = delete;
|
||||||
Index () = delete;
|
Index () = delete;
|
||||||
|
|
||||||
Index (std::string const& name,
|
Index (TRI_idx_iid_t id, Collection const* collection) :
|
||||||
struct TRI_vocbase_s* vocbase,
|
_id(id), _collection(collection){
|
||||||
TRI_transaction_type_e accessType,
|
|
||||||
TRI_index_t* index)
|
|
||||||
: name(name),
|
|
||||||
vocbase(vocbase),
|
|
||||||
collection(nullptr),
|
|
||||||
accessType(accessType),
|
|
||||||
_index(index){
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Index() {
|
~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 {
|
inline TRI_index_s* index () const {
|
||||||
TRI_ASSERT(_index != nullptr);
|
return TRI_LookupIndex(_collection->documentCollection(), _id);
|
||||||
return _index->_iid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief get the index id
|
/// @brief get the index type
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline TRI_idx_type_e type () const {
|
inline TRI_idx_type_e type () const {
|
||||||
TRI_ASSERT(_index != nullptr);
|
return this->index()->_type;
|
||||||
return _index->_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// anything else??
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- public variables
|
// --SECTION-- public variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
std::string const name;
|
TRI_idx_iid_t _id;
|
||||||
TRI_vocbase_t* vocbase;
|
Collection const* _collection;
|
||||||
TRI_vocbase_col_t* collection;
|
|
||||||
TRI_transaction_type_e accessType;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// --SECTION-- private variables
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
TRI_index_t* _index;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue