diff --git a/internal/core/src/index/BitmapIndex.cpp b/internal/core/src/index/BitmapIndex.cpp index dd8b703f40..95e51e676e 100644 --- a/internal/core/src/index/BitmapIndex.cpp +++ b/internal/core/src/index/BitmapIndex.cpp @@ -142,13 +142,19 @@ template void BitmapIndex::BuildArrayField(const std::vector& field_datas) { int64_t offset = 0; + using GetType = std::conditional_t || + std::is_same_v || + std::is_same_v, + int32_t, + T>; for (const auto& data : field_datas) { auto slice_row_num = data->get_num_rows(); for (size_t i = 0; i < slice_row_num; ++i) { auto array = reinterpret_cast(data->RawValue(i)); + for (size_t j = 0; j < array->length(); ++j) { - auto val = array->template get_data(j); + auto val = static_cast(array->template get_data(j)); data_[val].add(offset); } offset++; @@ -294,10 +300,12 @@ BitmapIndex::DeserializeIndexMeta(const uint8_t* data_ptr, template void -BitmapIndex::ChooseIndexBuildMode() { - if (data_.size() <= DEFAULT_BITMAP_INDEX_CARDINALITY_BOUND) { +BitmapIndex::ChooseIndexLoadMode(int64_t index_length) { + if (index_length <= DEFAULT_BITMAP_INDEX_CARDINALITY_BOUND) { + LOG_DEBUG("load bitmap index with bitset mode"); build_mode_ = BitmapIndexBuildMode::BITSET; } else { + LOG_DEBUG("load bitmap index with raw roaring mode"); build_mode_ = BitmapIndexBuildMode::ROARING; } } @@ -306,6 +314,7 @@ template void BitmapIndex::DeserializeIndexData(const uint8_t* data_ptr, size_t index_length) { + ChooseIndexLoadMode(index_length); for (size_t i = 0; i < index_length; ++i) { T key; memcpy(&key, data_ptr, sizeof(T)); @@ -315,11 +324,10 @@ BitmapIndex::DeserializeIndexData(const uint8_t* data_ptr, value = roaring::Roaring::read(reinterpret_cast(data_ptr)); data_ptr += value.getSizeInBytes(); - ChooseIndexBuildMode(); - if (build_mode_ == BitmapIndexBuildMode::BITSET) { bitsets_[key] = ConvertRoaringToBitset(value); - data_.erase(key); + } else { + data_[key] = value; } } } @@ -328,6 +336,7 @@ template <> void BitmapIndex::DeserializeIndexData(const uint8_t* data_ptr, size_t index_length) { + ChooseIndexLoadMode(index_length); for (size_t i = 0; i < index_length; ++i) { size_t key_size; memcpy(&key_size, data_ptr, sizeof(size_t)); @@ -340,7 +349,11 @@ BitmapIndex::DeserializeIndexData(const uint8_t* data_ptr, value = roaring::Roaring::read(reinterpret_cast(data_ptr)); data_ptr += value.getSizeInBytes(); - bitsets_[key] = ConvertRoaringToBitset(value); + if (build_mode_ == BitmapIndexBuildMode::BITSET) { + bitsets_[key] = ConvertRoaringToBitset(value); + } else { + data_[key] = value; + } } } diff --git a/internal/core/src/index/BitmapIndex.h b/internal/core/src/index/BitmapIndex.h index 9378ca85de..0a60181d60 100644 --- a/internal/core/src/index/BitmapIndex.h +++ b/internal/core/src/index/BitmapIndex.h @@ -146,7 +146,7 @@ class BitmapIndex : public ScalarIndex { DeserializeIndexData(const uint8_t* data_ptr, size_t index_length); void - ChooseIndexBuildMode(); + ChooseIndexLoadMode(int64_t index_length); bool ShouldSkip(const T lower_value, const T upper_value, const OpType op); diff --git a/internal/core/unittest/test_array_bitmap_index.cpp b/internal/core/unittest/test_array_bitmap_index.cpp index 78bf6fbcf1..d62b5cb758 100644 --- a/internal/core/unittest/test_array_bitmap_index.cpp +++ b/internal/core/unittest/test_array_bitmap_index.cpp @@ -194,8 +194,8 @@ class ArrayBitmapIndexTest : public testing::Test { auto serialized_bytes = insert_data.Serialize(storage::Remote); - auto log_path = fmt::format("{}/{}/{}/{}/{}/{}", - "test_array_bitmap", + auto log_path = fmt::format("/{}/{}/{}/{}/{}/{}", + "/tmp/test_array_bitmap", collection_id, partition_id, segment_id,