1
0
Fork 0

Unified lookup in PrimaryIndex to use identical format as HashIndex lookup does

This commit is contained in:
Michael Hackstein 2016-02-25 14:38:39 +01:00
parent 647cdc0ffe
commit 7b42fc7ae8
3 changed files with 30 additions and 11 deletions

View File

@ -85,11 +85,7 @@ TRI_doc_mptr_t* PrimaryIndexIterator::next() {
return nullptr;
}
VPackSlice eqMatch = _keys.at(_position++);
if (!eqMatch.hasKey(TRI_SLICE_KEY_EQUAL)) {
continue;
}
auto result = _index->lookupKey(_trx, eqMatch.get(TRI_SLICE_KEY_EQUAL));
auto result = _index->lookup(_trx, _keys.at(_position++));
if (result != nullptr) {
// found a result
@ -193,9 +189,21 @@ int PrimaryIndex::remove(arangodb::Transaction*, TRI_doc_mptr_t const*, bool) {
/// @brief looks up an element given a key
////////////////////////////////////////////////////////////////////////////////
TRI_doc_mptr_t* PrimaryIndex::lookupKey(arangodb::Transaction* trx,
VPackSlice const& slice) const {
return _primaryIndex->findByKey(trx, slice.begin());
TRI_doc_mptr_t* PrimaryIndex::lookup(arangodb::Transaction* trx,
VPackSlice const& slice) const {
if (!slice.isArray() && slice.length() == 1) {
// Invalid lookup
TRI_ASSERT(false);
return nullptr;
}
VPackSlice tmp = slice.at(0);
if (!tmp.isObject() || !tmp.hasKey(TRI_SLICE_KEY_EQUAL)) {
// Invalid lookup
TRI_ASSERT(false);
return nullptr;
}
tmp = tmp.get(TRI_SLICE_KEY_EQUAL);
return _primaryIndex->findByKey(trx, tmp.begin());
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -147,8 +147,13 @@ class PrimaryIndex final : public Index {
int remove(arangodb::Transaction*, TRI_doc_mptr_t const*,
bool) override final;
TRI_doc_mptr_t* lookupKey(arangodb::Transaction*,
VPackSlice const&) const;
//////////////////////////////////////////////////////////////////////////////
/// @brief looks up an element given a request Slice. Key hast to have the format
/// [{eq: _key}]
//////////////////////////////////////////////////////////////////////////////
TRI_doc_mptr_t* lookup(arangodb::Transaction*, VPackSlice const&) const;
TRI_doc_mptr_t* lookupKey(arangodb::Transaction*, char const*) const;

View File

@ -5313,8 +5313,14 @@ int TRI_document_collection_t::lookupDocument(
if (!key.isString()) {
return TRI_ERROR_INTERNAL;
}
VPackBuilder searchValue;
searchValue.openArray();
searchValue.openObject();
searchValue.add(TRI_SLICE_KEY_EQUAL, key);
searchValue.close();
searchValue.close();
header = primaryIndex()->lookupKey(trx, key);
header = primaryIndex()->lookup(trx, searchValue.slice());
if (header == nullptr) {
return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;