1
0
Fork 0

Merge branch 'aql-jmmh-conditions' of https://github.com/arangodb/arangodb into aql-jmmh-conditions

This commit is contained in:
Jan Steemann 2015-10-06 11:24:02 +02:00
commit 310442c8ac
11 changed files with 35 additions and 46 deletions

View File

@ -312,6 +312,7 @@ int IndexBlock::initialize () {
}
_nonConstExpressions.clear();
_alreadyReturned.clear();
// instantiate expressions:
auto instantiateExpression = [&] (size_t i, size_t j, size_t k, AstNode const* a) -> void {
@ -353,7 +354,7 @@ int IndexBlock::initialize () {
for (size_t i = 0; i < _condition->numMembers(); ++i) {
auto andCond = _condition->getMember(i);
for (size_t j = 0; j < andCond->numMembers(); ++j) {
auto leaf = andCond->getMember(i);
auto leaf = andCond->getMember(j);
// We only support binary conditions
TRI_ASSERT(leaf->numMembers() == 2);
@ -404,6 +405,9 @@ bool IndexBlock::initIndexes () {
ENTER_BLOCK
_flag = true;
// We start with a different context. Return documents found in the previous context again.
_alreadyReturned.clear();
// Find out about the actual values for the bounds in the variable bound case:
if (! _nonConstExpressions.empty()) {
@ -522,7 +526,7 @@ bool IndexBlock::readIndex (size_t atMost) {
try {
size_t nrSent = 0;
while (nrSent < atMost && _iterator != nullptr) {
TRI_doc_mptr_copy_t* indexElement = _iterator->next();
TRI_doc_mptr_t* indexElement = _iterator->next();
if (indexElement == nullptr) {
startNextIterator();
}
@ -530,9 +534,12 @@ bool IndexBlock::readIndex (size_t atMost) {
TRI_IF_FAILURE("IndexBlock::readIndex") {
THROW_ARANGO_EXCEPTION(TRI_ERROR_DEBUG);
}
if (_alreadyReturned.find(indexElement) == _alreadyReturned.end()) {
_alreadyReturned.emplace(indexElement);
_documents.emplace_back(*indexElement);
++nrSent;
_documents.emplace_back(*indexElement);
++nrSent;
}
++_engine->_stats.scannedIndex;
}
}

View File

@ -231,6 +231,12 @@ namespace triagens {
AstNode const* _condition;
////////////////////////////////////////////////////////////////////////////////
/// @brief set of already returned documents. Used to make the result distinct.
////////////////////////////////////////////////////////////////////////////////
std::unordered_set<TRI_doc_mptr_t*> _alreadyReturned;
////////////////////////////////////////////////////////////////////////////////
/// @brief _condition: holds the complete condition this Block can serve for
////////////////////////////////////////////////////////////////////////////////

View File

@ -341,7 +341,7 @@ static bool IsEqualElementEdgeToByKey (void const* left,
// -----------------------------------------------------------------------------
TRI_doc_mptr_copy_t* EdgeIndexIterator::next () {
TRI_doc_mptr_t* EdgeIndexIterator::next () {
if (_buffer == nullptr) {
// We start a new lookup
_buffer = _index->lookupByKey(&_searchValue, _batchSize);
@ -358,9 +358,7 @@ TRI_doc_mptr_copy_t* EdgeIndexIterator::next () {
if (_buffer->empty()) {
return nullptr;
}
TRI_doc_mptr_copy_t* res = static_cast<TRI_doc_mptr_copy_t*>(_buffer->at(_posInBuffer));
_posInBuffer++;
return res;
return _buffer->at(_posInBuffer++);
}
void EdgeIndexIterator::initCursor () {

View File

@ -54,7 +54,7 @@ namespace triagens {
typedef triagens::basics::AssocMulti<TRI_edge_header_t, TRI_doc_mptr_t, uint32_t, true> TRI_EdgeIndexHash_t;
TRI_doc_mptr_copy_t* next () override;
TRI_doc_mptr_t* next () override;
void initCursor () override;

View File

@ -121,7 +121,7 @@ static bool IsEqualKeyElementHash (TRI_index_search_value_t const* left,
// --SECTION-- public methods
// -----------------------------------------------------------------------------
TRI_doc_mptr_copy_t* HashIndexIterator::next () {
TRI_doc_mptr_t* HashIndexIterator::next () {
if (_buffer.empty()) {
_index->lookup(&_searchValue, _buffer);
if (_buffer.empty()) {
@ -129,8 +129,7 @@ TRI_doc_mptr_copy_t* HashIndexIterator::next () {
}
}
if (_posInBuffer < _buffer.size()) {
_posInBuffer++;
return &(_buffer[_posInBuffer - 1]);
return _buffer[_posInBuffer++];
}
return nullptr;
}
@ -400,14 +399,14 @@ int HashIndex::sizeHint (size_t size) {
////////////////////////////////////////////////////////////////////////////////
int HashIndex::lookup (TRI_index_search_value_t* searchValue,
std::vector<TRI_doc_mptr_copy_t>& documents) const {
std::vector<TRI_doc_mptr_t*>& documents) const {
if (_unique) {
TRI_index_element_t* found = _uniqueArray->_hashArray->findByKey(searchValue);
if (found != nullptr) {
// unique hash index: maximum number is 1
documents.emplace_back(*(found->document()));
documents.emplace_back(found->document());
}
return TRI_ERROR_NO_ERROR;
}
@ -422,7 +421,7 @@ int HashIndex::lookup (TRI_index_search_value_t* searchValue,
if (results != nullptr) {
try {
for (size_t i = 0; i < results->size(); i++) {
documents.emplace_back(*((*results)[i]->document()));
documents.emplace_back((*results)[i]->document());
}
delete results;
}

View File

@ -65,7 +65,7 @@ namespace triagens {
~HashIndexIterator() {};
TRI_doc_mptr_copy_t* next () override;
TRI_doc_mptr_t* next () override;
void initCursor () override;
@ -73,7 +73,7 @@ namespace triagens {
HashIndex const* _index;
TRI_index_search_value_t _searchValue;
std::vector<TRI_doc_mptr_copy_t> _buffer;
std::vector<TRI_doc_mptr_t*> _buffer;
size_t _posInBuffer;
};
@ -143,7 +143,7 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
int lookup (TRI_index_search_value_t*,
std::vector<TRI_doc_mptr_copy_t>&) const;
std::vector<TRI_doc_mptr_t*>&) const;
////////////////////////////////////////////////////////////////////////////////
/// @brief locates entries in the hash index given shaped json objects

View File

@ -472,28 +472,11 @@ IndexIterator* Index::iteratorForCondition (
IndexIterator::~IndexIterator () {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief default implementation for size
////////////////////////////////////////////////////////////////////////////////
size_t IndexIterator::size () const {
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief default implementation for hasNext
////////////////////////////////////////////////////////////////////////////////
bool IndexIterator::hasNext () const {
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief default implementation for next
////////////////////////////////////////////////////////////////////////////////
TRI_doc_mptr_copy_t* IndexIterator::next () {
TRI_doc_mptr_t* IndexIterator::next () {
return nullptr;
}

View File

@ -165,11 +165,7 @@ namespace triagens {
virtual ~IndexIterator ();
virtual size_t size () const;
virtual bool hasNext () const;
virtual TRI_doc_mptr_copy_t* next ();
virtual TRI_doc_mptr_t* next ();
virtual void initCursor ();
};

View File

@ -82,12 +82,12 @@ static bool IsEqualElementElement (TRI_doc_mptr_t const* left,
// --SECTION-- public methods
// -----------------------------------------------------------------------------
TRI_doc_mptr_copy_t* PrimaryIndexIterator::next () {
TRI_doc_mptr_t* PrimaryIndexIterator::next () {
if (_hasReturned) {
return nullptr;
}
_hasReturned = true;
return static_cast<TRI_doc_mptr_copy_t*>(_index->lookupKey(_key));
return _index->lookupKey(_key);
}
void PrimaryIndexIterator::initCursor () {

View File

@ -65,7 +65,7 @@ namespace triagens {
~PrimaryIndexIterator () {};
TRI_doc_mptr_copy_t* next () override;
TRI_doc_mptr_t* next () override;
void initCursor () override;

View File

@ -1244,7 +1244,7 @@ static void ByExampleHashIndexQuery (SingleCollectionReadOnlyTransaction& trx,
}
// find the matches
std::vector<TRI_doc_mptr_copy_t> list;
std::vector<TRI_doc_mptr_t*> list;
static_cast<triagens::arango::HashIndex*>(idx)->lookup(&searchValue, list);
DestroySearchValue(shaper->memoryZone(), searchValue);
@ -1261,7 +1261,7 @@ static void ByExampleHashIndexQuery (SingleCollectionReadOnlyTransaction& trx,
for (uint64_t i = s; i < e; ++i) {
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx,
collection->_cid,
list[i].getDataPtr());
list[i]->getDataPtr());
if (doc.IsEmpty()) {
error = true;