From 1d4e5e1c8a700523fa5558334025a28f5087dc45 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 24 Nov 2016 13:45:38 +0100 Subject: [PATCH] fixed array index behavior on hash collisions --- arangod/Indexes/HashIndex.cpp | 4 +++- arangod/Indexes/HashIndex.h | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/arangod/Indexes/HashIndex.cpp b/arangod/Indexes/HashIndex.cpp index 0e0fe8e7c3..c8c39efa72 100644 --- a/arangod/Indexes/HashIndex.cpp +++ b/arangod/Indexes/HashIndex.cpp @@ -233,6 +233,7 @@ static bool IsEqualElementElementMulti(void* userData, VPackSlice rightData = right->slice(context, i); int res = arangodb::basics::VelocyPackHelper::compare(leftData, rightData, false); + if (res != 0) { return false; } @@ -263,6 +264,7 @@ static bool IsEqualKeyElementMulti(void* userData, VPackSlice const rightVPack = right->slice(context, i); int res = arangodb::basics::VelocyPackHelper::compare(leftVPack, rightVPack, false); + if (res != 0) { return false; } @@ -480,7 +482,7 @@ HashIndex::HashIndex(TRI_idx_iid_t iid, LogicalCollection* collection, } auto func = std::make_unique(); - auto compare = std::make_unique(_paths.size()); + auto compare = std::make_unique(_paths.size(), _useExpansion); if (_unique) { auto array = std::make_unique( diff --git a/arangod/Indexes/HashIndex.h b/arangod/Indexes/HashIndex.h index 8680b51a25..2e0eeac8bd 100644 --- a/arangod/Indexes/HashIndex.h +++ b/arangod/Indexes/HashIndex.h @@ -244,16 +244,17 @@ class HashIndex final : public PathBasedIndex { /// @brief determines if a key corresponds to an element class IsEqualElementElementByKey { size_t _numFields; + bool _allowExpansion; public: - explicit IsEqualElementElementByKey(size_t n) : _numFields(n) {} + IsEqualElementElementByKey(size_t n, bool allowExpansion) : _numFields(n), _allowExpansion(allowExpansion) {} bool operator()(void* userData, HashIndexElement const* left, HashIndexElement const* right) { TRI_ASSERT(left->revisionId() != 0); TRI_ASSERT(right->revisionId() != 0); - if (left->revisionId() == right->revisionId()) { + if (!_allowExpansion && left->revisionId() == right->revisionId()) { return true; } @@ -264,6 +265,7 @@ class HashIndex final : public PathBasedIndex { VPackSlice rightData = right->slice(context, i); int res = arangodb::basics::VelocyPackHelper::compare(leftData, rightData, false); + if (res != 0) { return false; }