1
0
Fork 0

truncate optimization

This commit is contained in:
Jan Steemann 2016-02-22 16:52:18 +01:00
parent 3e2e14d800
commit 49181147e4
4 changed files with 33 additions and 3 deletions

View File

@ -354,6 +354,11 @@ void PrimaryIndex::invokeOnAllElements(
_primaryIndex->invokeOnAllElements(work);
}
void PrimaryIndex::invokeOnAllElementsForRemoval(
std::function<void(TRI_doc_mptr_t*)> work) {
_primaryIndex->invokeOnAllElementsForRemoval(work);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks whether the index supports the condition
////////////////////////////////////////////////////////////////////////////////

View File

@ -238,6 +238,7 @@ class PrimaryIndex final : public Index {
static uint64_t calculateHash(arangodb::Transaction*, uint8_t const*);
void invokeOnAllElements(std::function<void(TRI_doc_mptr_t*)>);
void invokeOnAllElementsForRemoval(std::function<void(TRI_doc_mptr_t*)>);
bool supportsFilterCondition(arangodb::aql::AstNode const*,
arangodb::aql::Variable const*, size_t, size_t&,

View File

@ -1481,7 +1481,7 @@ OperationResult Transaction::truncateLocal(std::string const& collectionName,
};
try {
primaryIndex->invokeOnAllElements(callback);
primaryIndex->invokeOnAllElementsForRemoval(callback);
}
catch (basics::Exception const& ex) {
unlock(trxCollection(cid), TRI_TRANSACTION_WRITE);

View File

@ -841,13 +841,33 @@ class AssocUnique {
return old;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief a method to iterate over all elements in the hash. this method
/// can NOT be used for deleting elements
//////////////////////////////////////////////////////////////////////////////
void invokeOnAllElements(CallbackElementFuncType callback) {
for (auto& b : _buckets) {
if (b._table == nullptr) {
continue;
}
for (size_t i = 0; i < b._nrAlloc; ++i) {
if (b._table[i] == nullptr) {
continue;
}
// don't increment i
callback(b._table[i]);
}
}
}
//////////////////////////////////////////////////////////////////////////////
/// @brief a method to iterate over all elements in the hash. this method
/// can be used for deleting elements as well
//////////////////////////////////////////////////////////////////////////////
void invokeOnAllElements(CallbackElementFuncType callback) {
void invokeOnAllElementsForRemoval(CallbackElementFuncType callback) {
for (auto& b : _buckets) {
if (b._table == nullptr) {
continue;
@ -857,11 +877,15 @@ class AssocUnique {
++i;
continue;
}
// don't increment i
// intentionally don't increment i
auto old = b._table[i];
callback(b._table[i]);
if (b._nrUsed == 0) {
break;
}
if (b._table[i] == old) {
++i;
}
}
}
}