mirror of https://gitee.com/bigwinds/arangodb
Fixed the resizing of AssocUnique. It was different from AssocMulti which cased the nonUnique index to be faster than the unique one
This commit is contained in:
parent
fa948660b1
commit
1afd19e550
|
@ -204,9 +204,9 @@ HashIndex::HashIndex (TRI_idx_iid_t iid,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<HashElementFunc> func(new HashElementFunc(_paths.size()));
|
std::unique_ptr<HashElementFunc> func(new HashElementFunc(_paths.size()));
|
||||||
|
std::unique_ptr<IsEqualElementElementByKey> compare(new IsEqualElementElementByKey(_paths.size()));
|
||||||
|
|
||||||
if (unique) {
|
if (unique) {
|
||||||
std::unique_ptr<IsEqualElementElementByKey> compare(new IsEqualElementElementByKey(_paths.size()));
|
|
||||||
std::unique_ptr<TRI_HashArray_t> array(new TRI_HashArray_t(HashKey,
|
std::unique_ptr<TRI_HashArray_t> array(new TRI_HashArray_t(HashKey,
|
||||||
*(func.get()),
|
*(func.get()),
|
||||||
IsEqualKeyElementHash,
|
IsEqualKeyElementHash,
|
||||||
|
@ -221,8 +221,6 @@ HashIndex::HashIndex (TRI_idx_iid_t iid,
|
||||||
else {
|
else {
|
||||||
_multiArray = nullptr;
|
_multiArray = nullptr;
|
||||||
|
|
||||||
std::unique_ptr<IsEqualElementElementByKey> compare(new IsEqualElementElementByKey(_paths.size()));
|
|
||||||
|
|
||||||
std::unique_ptr<TRI_HashArrayMulti_t> array(new TRI_HashArrayMulti_t(HashKey,
|
std::unique_ptr<TRI_HashArrayMulti_t> array(new TRI_HashArrayMulti_t(HashKey,
|
||||||
*(func.get()),
|
*(func.get()),
|
||||||
IsEqualKeyElement,
|
IsEqualKeyElement,
|
||||||
|
@ -234,9 +232,9 @@ HashIndex::HashIndex (TRI_idx_iid_t iid,
|
||||||
|
|
||||||
_multiArray = new HashIndex::MultiArray(array.get(), func.get(), compare.get());
|
_multiArray = new HashIndex::MultiArray(array.get(), func.get(), compare.get());
|
||||||
|
|
||||||
compare.release();
|
|
||||||
array.release();
|
array.release();
|
||||||
}
|
}
|
||||||
|
compare.release();
|
||||||
|
|
||||||
func.release();
|
func.release();
|
||||||
}
|
}
|
||||||
|
@ -552,6 +550,7 @@ int HashIndex::insertMulti (TRI_doc_mptr_t const* doc,
|
||||||
for (auto& hashElement : elements) {
|
for (auto& hashElement : elements) {
|
||||||
FreeElement(hashElement);
|
FreeElement(hashElement);
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto work = [this] (TRI_index_element_t* element, bool isRollback) -> int {
|
auto work = [this] (TRI_index_element_t* element, bool isRollback) -> int {
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
// #define TRI_CHECK_MULTI_POINTER_HASH 1
|
// #define TRI_CHECK_MULTI_POINTER_HASH 1
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
#include "Basics/prime-numbers.h"
|
|
||||||
#include "Basics/JsonHelper.h"
|
#include "Basics/JsonHelper.h"
|
||||||
#include "Basics/logging.h"
|
#include "Basics/logging.h"
|
||||||
|
#include "Basics/memory-map.h"
|
||||||
#include "Basics/Mutex.h"
|
#include "Basics/Mutex.h"
|
||||||
#include "Basics/MutexLocker.h"
|
#include "Basics/MutexLocker.h"
|
||||||
#include "Basics/memory-map.h"
|
#include "Basics/prime-numbers.h"
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
namespace basics {
|
namespace basics {
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
#include "Basics/gcd.h"
|
#include "Basics/gcd.h"
|
||||||
#include "Basics/JsonHelper.h"
|
#include "Basics/JsonHelper.h"
|
||||||
#include "Basics/logging.h"
|
#include "Basics/logging.h"
|
||||||
|
#include "Basics/memory-map.h"
|
||||||
#include "Basics/MutexLocker.h"
|
#include "Basics/MutexLocker.h"
|
||||||
|
#include "Basics/prime-numbers.h"
|
||||||
#include "Basics/random.h"
|
#include "Basics/random.h"
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
|
@ -230,9 +232,21 @@ namespace triagens {
|
||||||
|
|
||||||
TRI_ASSERT(targetSize > 0);
|
TRI_ASSERT(targetSize > 0);
|
||||||
|
|
||||||
|
targetSize = TRI_NearPrime(targetSize);
|
||||||
|
|
||||||
// This might throw, is catched outside
|
// This might throw, is catched outside
|
||||||
b._table = new Element* [targetSize];
|
b._table = new Element* [targetSize];
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
if (b._nrAlloc > 1000000) {
|
||||||
|
uintptr_t mem = reinterpret_cast<uintptr_t>(b._table);
|
||||||
|
uintptr_t pageSize = getpagesize();
|
||||||
|
mem = (mem / pageSize) * pageSize;
|
||||||
|
void* memptr = reinterpret_cast<void*>(mem);
|
||||||
|
TRI_MMFileAdvise(memptr, b._nrAlloc * sizeof(Element*),
|
||||||
|
TRI_MADVISE_RANDOM);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
for (uint64_t i = 0; i < targetSize; i++) {
|
for (uint64_t i = 0; i < targetSize; i++) {
|
||||||
b._table[i] = nullptr;
|
b._table[i] = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -390,11 +404,14 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int resize (size_t size) {
|
int resize (size_t size) {
|
||||||
|
size /= _buckets.size();
|
||||||
for (auto& b : _buckets) {
|
for (auto& b : _buckets) {
|
||||||
|
if (2 * (2 * size + 1) < 3 * b._nrUsed) {
|
||||||
|
return TRI_ERROR_BAD_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resizeInternal(b,
|
resizeInternal(b, 2 * size + 1, false);
|
||||||
(uint64_t) (3 * size / 2 + 1) / _buckets.size(),
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return TRI_ERROR_OUT_OF_MEMORY;
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
Loading…
Reference in New Issue