Skip to content

Commit

Permalink
Merge pull request #3066 from kuzudb/hash-index-reserve-fix
Browse files Browse the repository at this point in the history
Fix Hash index split slot ID when reserving a number of slots which are a power of two
  • Loading branch information
benjaminwinger committed Mar 18, 2024
2 parents f12e5e7 + 2a3012c commit 826927e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/include/common/case_insensitive_map.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstdint>
#include <string>
#include <unordered_map>

Expand Down
7 changes: 5 additions & 2 deletions src/storage/index/hash_index_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ void HashIndexBuilder<T>::bulkReserve(uint32_t numEntries_) {
// Build from scratch.
auto numRequiredSlots = (numRequiredEntries + getSlotCapacity<T>() - 1) / getSlotCapacity<T>();
auto numSlotsOfCurrentLevel = 1u << this->indexHeader->currentLevel;
while ((numSlotsOfCurrentLevel << 1) < numRequiredSlots) {
while ((numSlotsOfCurrentLevel << 1) <= numRequiredSlots) {
this->indexHeader->incrementLevel();
numSlotsOfCurrentLevel <<= 1;
}
if (numRequiredSlots > numSlotsOfCurrentLevel) {
if (numRequiredSlots >= numSlotsOfCurrentLevel) {
this->indexHeader->nextSplitSlotId = numRequiredSlots - numSlotsOfCurrentLevel;
}
// The next slot to split should always be within the slots covered by the current level
// The level should be increased if it goes beyond that point
KU_ASSERT(this->indexHeader->nextSplitSlotId <= this->indexHeader->levelHashMask);
auto existingSlots = pSlots->getNumElements();
if (numRequiredSlots > existingSlots) {
allocatePSlots(numRequiredSlots - existingSlots);
Expand Down

0 comments on commit 826927e

Please sign in to comment.