mirror of https://github.com/milvus-io/milvus.git
related: #29132 Signed-off-by: MrPresent-Han <chun.han@zilliz.com>pull/29306/head
parent
56d7225673
commit
bfca0a7926
|
@ -17,6 +17,7 @@ set(INDEX_FILES
|
|||
VectorDiskIndex.cpp
|
||||
ScalarIndex.cpp
|
||||
ScalarIndexSort.cpp
|
||||
SkipIndex.cpp
|
||||
)
|
||||
|
||||
milvus_add_pkg_config("milvus_index")
|
||||
|
|
|
@ -17,11 +17,12 @@ static const FieldChunkMetrics defaultFieldChunkMetrics;
|
|||
|
||||
const FieldChunkMetrics&
|
||||
SkipIndex::GetFieldChunkMetrics(milvus::FieldId field_id, int chunk_id) const {
|
||||
std::shared_lock lck(mutex_);
|
||||
auto field_metrics = fieldChunkMetrics_.find(field_id);
|
||||
if (field_metrics != fieldChunkMetrics_.end()) {
|
||||
auto field_chunk_metrics = field_metrics->second.find(chunk_id);
|
||||
if (field_chunk_metrics != field_metrics->second.end()) {
|
||||
return field_chunk_metrics->second;
|
||||
return *(field_chunk_metrics->second.get());
|
||||
}
|
||||
}
|
||||
return defaultFieldChunkMetrics;
|
||||
|
@ -33,17 +34,18 @@ SkipIndex::LoadPrimitive(milvus::FieldId field_id,
|
|||
milvus::DataType data_type,
|
||||
const void* chunk_data,
|
||||
int64_t count) {
|
||||
FieldChunkMetrics chunkMetrics;
|
||||
auto chunkMetrics = std::make_unique<FieldChunkMetrics>();
|
||||
|
||||
if (count > 0) {
|
||||
chunkMetrics.hasValue_ = true;
|
||||
chunkMetrics->hasValue_ = true;
|
||||
switch (data_type) {
|
||||
case DataType::INT8: {
|
||||
const int8_t* typedData =
|
||||
static_cast<const int8_t*>(chunk_data);
|
||||
std::pair<int8_t, int8_t> minMax =
|
||||
ProcessFieldMetrics<int8_t>(typedData, count);
|
||||
chunkMetrics.min_ = Metrics(minMax.first);
|
||||
chunkMetrics.max_ = Metrics(minMax.second);
|
||||
chunkMetrics->min_ = Metrics(minMax.first);
|
||||
chunkMetrics->max_ = Metrics(minMax.second);
|
||||
break;
|
||||
}
|
||||
case DataType::INT16: {
|
||||
|
@ -51,8 +53,8 @@ SkipIndex::LoadPrimitive(milvus::FieldId field_id,
|
|||
static_cast<const int16_t*>(chunk_data);
|
||||
std::pair<int16_t, int16_t> minMax =
|
||||
ProcessFieldMetrics<int16_t>(typedData, count);
|
||||
chunkMetrics.min_ = Metrics(minMax.first);
|
||||
chunkMetrics.max_ = Metrics(minMax.second);
|
||||
chunkMetrics->min_ = Metrics(minMax.first);
|
||||
chunkMetrics->max_ = Metrics(minMax.second);
|
||||
break;
|
||||
}
|
||||
case DataType::INT32: {
|
||||
|
@ -60,8 +62,8 @@ SkipIndex::LoadPrimitive(milvus::FieldId field_id,
|
|||
static_cast<const int32_t*>(chunk_data);
|
||||
std::pair<int32_t, int32_t> minMax =
|
||||
ProcessFieldMetrics<int32_t>(typedData, count);
|
||||
chunkMetrics.min_ = Metrics(minMax.first);
|
||||
chunkMetrics.max_ = Metrics(minMax.second);
|
||||
chunkMetrics->min_ = Metrics(minMax.first);
|
||||
chunkMetrics->max_ = Metrics(minMax.second);
|
||||
break;
|
||||
}
|
||||
case DataType::INT64: {
|
||||
|
@ -69,16 +71,16 @@ SkipIndex::LoadPrimitive(milvus::FieldId field_id,
|
|||
static_cast<const int64_t*>(chunk_data);
|
||||
std::pair<int64_t, int64_t> minMax =
|
||||
ProcessFieldMetrics<int64_t>(typedData, count);
|
||||
chunkMetrics.min_ = Metrics(minMax.first);
|
||||
chunkMetrics.max_ = Metrics(minMax.second);
|
||||
chunkMetrics->min_ = Metrics(minMax.first);
|
||||
chunkMetrics->max_ = Metrics(minMax.second);
|
||||
break;
|
||||
}
|
||||
case DataType::FLOAT: {
|
||||
const float* typedData = static_cast<const float*>(chunk_data);
|
||||
std::pair<float, float> minMax =
|
||||
ProcessFieldMetrics<float>(typedData, count);
|
||||
chunkMetrics.min_ = Metrics(minMax.first);
|
||||
chunkMetrics.max_ = Metrics(minMax.second);
|
||||
chunkMetrics->min_ = Metrics(minMax.first);
|
||||
chunkMetrics->max_ = Metrics(minMax.second);
|
||||
break;
|
||||
}
|
||||
case DataType::DOUBLE: {
|
||||
|
@ -86,13 +88,20 @@ SkipIndex::LoadPrimitive(milvus::FieldId field_id,
|
|||
static_cast<const double*>(chunk_data);
|
||||
std::pair<double, double> minMax =
|
||||
ProcessFieldMetrics<double>(typedData, count);
|
||||
chunkMetrics.min_ = Metrics(minMax.first);
|
||||
chunkMetrics.max_ = Metrics(minMax.second);
|
||||
chunkMetrics->min_ = Metrics(minMax.first);
|
||||
chunkMetrics->max_ = Metrics(minMax.second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldChunkMetrics_[field_id][chunk_id] = chunkMetrics;
|
||||
std::unique_lock lck(mutex_);
|
||||
if (fieldChunkMetrics_.count(field_id) == 0) {
|
||||
fieldChunkMetrics_.insert(std::make_pair(
|
||||
field_id,
|
||||
std::unordered_map<int64_t, std::unique_ptr<FieldChunkMetrics>>()));
|
||||
}
|
||||
|
||||
fieldChunkMetrics_[field_id].emplace(chunk_id, std::move(chunkMetrics));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -100,9 +109,9 @@ SkipIndex::LoadString(milvus::FieldId field_id,
|
|||
int64_t chunk_id,
|
||||
const milvus::VariableColumn<std::string>& var_column) {
|
||||
int num_rows = var_column.NumRows();
|
||||
FieldChunkMetrics chunkMetrics;
|
||||
auto chunkMetrics = std::make_unique<FieldChunkMetrics>();
|
||||
if (num_rows > 0) {
|
||||
chunkMetrics.hasValue_ = true;
|
||||
chunkMetrics->hasValue_ = true;
|
||||
std::string_view min_string = var_column.RawAt(0);
|
||||
std::string_view max_string = var_column.RawAt(0);
|
||||
for (size_t i = 1; i < num_rows; i++) {
|
||||
|
@ -114,10 +123,16 @@ SkipIndex::LoadString(milvus::FieldId field_id,
|
|||
max_string = val;
|
||||
}
|
||||
}
|
||||
chunkMetrics.min_ = Metrics(min_string);
|
||||
chunkMetrics.max_ = Metrics(max_string);
|
||||
chunkMetrics->min_ = Metrics(min_string);
|
||||
chunkMetrics->max_ = Metrics(max_string);
|
||||
}
|
||||
fieldChunkMetrics_[field_id][chunk_id] = chunkMetrics;
|
||||
std::unique_lock lck(mutex_);
|
||||
if (fieldChunkMetrics_.count(field_id) == 0) {
|
||||
fieldChunkMetrics_.insert(std::make_pair(
|
||||
field_id,
|
||||
std::unordered_map<int64_t, std::unique_ptr<FieldChunkMetrics>>()));
|
||||
}
|
||||
fieldChunkMetrics_[field_id].emplace(chunk_id, std::move(chunkMetrics));
|
||||
}
|
||||
|
||||
} // namespace milvus
|
|
@ -35,12 +35,6 @@ struct FieldChunkMetrics {
|
|||
|
||||
class SkipIndex {
|
||||
public:
|
||||
SkipIndex() {
|
||||
fieldChunkMetrics_ = std::unordered_map<
|
||||
FieldId,
|
||||
std::unordered_map<int64_t, FieldChunkMetrics>>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
CanSkipUnaryRange(FieldId field_id,
|
||||
|
@ -245,7 +239,10 @@ class SkipIndex {
|
|||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<FieldId, std::unordered_map<int64_t, FieldChunkMetrics>>
|
||||
std::unordered_map<
|
||||
FieldId,
|
||||
std::unordered_map<int64_t, std::unique_ptr<FieldChunkMetrics>>>
|
||||
fieldChunkMetrics_;
|
||||
mutable std::shared_mutex mutex_;
|
||||
};
|
||||
} // namespace milvus
|
|
@ -36,7 +36,7 @@
|
|||
#include "segcore/SegmentGrowingImpl.h"
|
||||
#include "simdjson/error.h"
|
||||
#include "query/PlanProto.h"
|
||||
#include "segcore/SkipIndex.h"
|
||||
#include "index/SkipIndex.h"
|
||||
#include "simd/hook.h"
|
||||
#include "index/Meta.h"
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@ set(SEGCORE_FILES
|
|||
ScalarIndex.cpp
|
||||
TimestampIndex.cpp
|
||||
Utils.cpp
|
||||
ConcurrentVector.cpp
|
||||
SkipIndex.cpp)
|
||||
ConcurrentVector.cpp)
|
||||
add_library(milvus_segcore SHARED ${SEGCORE_FILES})
|
||||
|
||||
target_link_libraries(milvus_segcore milvus_query milvus_exec ${OpenMP_CXX_FLAGS} milvus-storage)
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "pb/schema.pb.h"
|
||||
#include "pb/segcore.pb.h"
|
||||
#include "index/IndexInfo.h"
|
||||
#include "SkipIndex.h"
|
||||
#include "index/SkipIndex.h"
|
||||
#include "mmap/Column.h"
|
||||
|
||||
namespace milvus::segcore {
|
||||
|
|
Loading…
Reference in New Issue