fix: Fix performance issue and use after free bug (#39343)

cherry pick some fixes in https://github.com/milvus-io/milvus/pull/39249

Signed-off-by: sunby <sunbingyi1992@gmail.com>
pull/39390/head
Bingyi Sun 2025-01-17 11:51:03 +08:00 committed by GitHub
parent 47e410feb1
commit 56cb1683eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 10 deletions

View File

@ -684,10 +684,13 @@ class SegmentExpr : public Expr {
if constexpr (std::is_same_v<T, std::string_view> || if constexpr (std::is_same_v<T, std::string_view> ||
std::is_same_v<T, Json>) { std::is_same_v<T, Json>) {
if (segment_->type() == SegmentType::Sealed) { if (segment_->type() == SegmentType::Sealed) {
valid_data = segment_ auto batch_views = segment_->get_batch_views<T>(
->get_batch_views<T>( field_id_, i, data_pos, size);
field_id_, i, data_pos, size) valid_data = batch_views.second.data();
.second.data(); ApplyValidData(valid_data,
res + processed_size,
valid_res + processed_size,
size);
} }
} else { } else {
auto chunk = segment_->chunk_data<T>(field_id_, i); auto chunk = segment_->chunk_data<T>(field_id_, i);
@ -695,12 +698,12 @@ class SegmentExpr : public Expr {
if (valid_data != nullptr) { if (valid_data != nullptr) {
valid_data += data_pos; valid_data += data_pos;
} }
}
ApplyValidData(valid_data, ApplyValidData(valid_data,
res + processed_size, res + processed_size,
valid_res + processed_size, valid_res + processed_size,
size); size);
} }
}
processed_size += size; processed_size += size;
if (processed_size >= batch_size_) { if (processed_size >= batch_size_) {

View File

@ -138,8 +138,8 @@ SegmentChunkReader::GetChunkDataAccessor<std::string>(
current_chunk_size = current_chunk_size =
segment_->chunk_size(field_id, current_chunk_id); segment_->chunk_size(field_id, current_chunk_id);
} }
auto chunk_data = chunk_info.first; auto& chunk_data = chunk_info.first;
auto chunk_valid_data = chunk_info.second; auto& chunk_valid_data = chunk_info.second;
if (current_chunk_pos < chunk_valid_data.size() && if (current_chunk_pos < chunk_valid_data.size() &&
!chunk_valid_data[current_chunk_pos]) { !chunk_valid_data[current_chunk_pos]) {
current_chunk_pos++; current_chunk_pos++;