mirror of https://gitee.com/bigwinds/arangodb
Unified lookup in PrimaryIndex to use identical format as HashIndex lookup does
This commit is contained in:
parent
647cdc0ffe
commit
7b42fc7ae8
|
@ -85,11 +85,7 @@ TRI_doc_mptr_t* PrimaryIndexIterator::next() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VPackSlice eqMatch = _keys.at(_position++);
|
auto result = _index->lookup(_trx, _keys.at(_position++));
|
||||||
if (!eqMatch.hasKey(TRI_SLICE_KEY_EQUAL)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto result = _index->lookupKey(_trx, eqMatch.get(TRI_SLICE_KEY_EQUAL));
|
|
||||||
|
|
||||||
if (result != nullptr) {
|
if (result != nullptr) {
|
||||||
// found a result
|
// 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
|
/// @brief looks up an element given a key
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TRI_doc_mptr_t* PrimaryIndex::lookupKey(arangodb::Transaction* trx,
|
TRI_doc_mptr_t* PrimaryIndex::lookup(arangodb::Transaction* trx,
|
||||||
VPackSlice const& slice) const {
|
VPackSlice const& slice) const {
|
||||||
return _primaryIndex->findByKey(trx, slice.begin());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -147,8 +147,13 @@ class PrimaryIndex final : public Index {
|
||||||
int remove(arangodb::Transaction*, TRI_doc_mptr_t const*,
|
int remove(arangodb::Transaction*, TRI_doc_mptr_t const*,
|
||||||
bool) override final;
|
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;
|
TRI_doc_mptr_t* lookupKey(arangodb::Transaction*, char const*) const;
|
||||||
|
|
||||||
|
|
|
@ -5313,8 +5313,14 @@ int TRI_document_collection_t::lookupDocument(
|
||||||
if (!key.isString()) {
|
if (!key.isString()) {
|
||||||
return TRI_ERROR_INTERNAL;
|
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) {
|
if (header == nullptr) {
|
||||||
return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;
|
||||||
|
|
Loading…
Reference in New Issue